How could I get only the 2nd product in this query?
$loop = new WP_Query( [
'post_type' => 'product',
'posts_per_page' => 1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
),
),
] );
How could I get only the 2nd product in this query?
$loop = new WP_Query( [
'post_type' => 'product',
'posts_per_page' => 1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
),
),
] );
Share
Improve this question
edited Dec 1, 2019 at 8:31
aye cee
asked Dec 1, 2019 at 6:22
aye ceeaye cee
15912 bronze badges
1 Answer
Reset to default 3I figured out you can use 'offset' => 1,
to skip 1 post and get the 2nd. Change the number to however many posts you want to skip. ie. set it to 2 to get the 3rd.
$loop = new WP_Query( [
'post_type' => 'product',
'posts_per_page' => 1,
'offset' => 1,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
] );