Reference a prior WP_Query
-
A site I’m building has a blog feed for a news category. Simple enough. But I also have a sidebar feed that pulls from that news category, therefore when the news page is loaded, the same items show up twice.*
I would like to make it so my news feed page* takes the two most recent items, and from that point, the sidebar will use the next-most recent remaining 3 items, and only if the current page is news of course*.
I tried this, knowing it proably wouldn’t work:
//page-news.php which includes sidebar.php $latest_news = new WP_Query('cat="16"&posts_per_page="2"'); //loop and feed for news, working just fine //then later... (sidebar.php) if( $latest_news->have_posts() ) : while( $latest_news->have_posts() ) : $latest_news->the_post() //nothing shows up here
So this confirmed that $latest_news gets lost between the two php files. How would I reference that prior query AND remove the 2 posts that were already used?
*EDITS for clarity
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Reference a prior WP_Query’ is closed to new replies.