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

wp query - How to duplicate 5 posts out of WP_Query results?

programmeradmin2浏览0评论

If I have done a posts query which has fetched a long list of posts in to the WP_Object $all_posts, how, during the output loop, can I pull the next five posts of $all_posts in to new WP_Object $five_posts?

I'm already successfully using a counter, $i, in the loop to identify the position at which this should occur.

What I don't understand is how to get the next five posts in to a WP_Object.

I have tried...

$five_posts = new WP_Query();
$five_posts->posts = array_slice(
                            $all_posts->posts, 
                            $all_posts->current_position, 
                            $all_posts->current_position + 5
                        );

But that results only in the [posts] part of the query, sliced as an array, and omits the actual query data, which I'd like to retain.

So, basically, how do I extract five posts out of $all_posts in a way that maintains $five_posts as a full WP_Query object?

发布评论

评论列表(0)

  1. 暂无评论