bobdobbs
Member
Posted 7 months ago #
I've grabbed posts using an instance of WP_Query.
I have the posts in $my_query. I have used them initially to populate a sidebar.
Now I want to reuse the posts in $my_query. I have rewound it.
How do I limit the new loop, so that only one post is produced?
possibly, add break; before the endwhile; of the second loop.
details depend on your code - you can paste the full code into a http://pastebin.com/ and post the link to it here (how to, see http://codex.wordpress.org/Forum_Welcome#Posting_Code ), for somone to check this.
Navaratnam
Member
Posted 7 months ago #
declare a variable and limit it.
$i = 0;
WP Loop bigins
if ($i < 1){
Display the post
}
$i++;
WP Loop ends
bobdobbs
Member
Posted 7 months ago #
Thanks for the help.
Hacking away at this has helped me to get a bit more used to wp and php (and the potential frustrations of working with both of them)
The solution I used was given to me on #wordpress by dc5ala. He suggested this:
($myquery->have_posts()) {
$myquery->the_post(); the_title(); } wp_reset_postdata();
This worked.