最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - wp_query get the 2nd post

programmeradmin1浏览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',
        ] );

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论