php - wp_query get the 2nd post

admin2025-04-18  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',
                ),
            ),
        ] );

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
Add a comment  | 

1 Answer 1

Reset to default 3

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',
        ] );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744951390a276356.html

最新回复(0)