0

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',
                ),
            ),
        ] );
2

I 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',
        ] );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.