Turns out I didn’t follow the instructions in the manual to the letter: I seem to have declared global $post
too early. I don’t entirely see through this but it works fine now using this code:
$eventsPosts = $wpdb->get_results($querystr, OBJECT);
if ($eventsPosts)
{
global $post;
foreach ($eventsPosts as $post)
{
setup_postdata($post);
the_title(); // or whatever - the loop functions work
}
}
Related Posts:
- Is it necessary to reset the query after using get_posts()?
- Post Loop not Returning Permalink
- Get posts that matches specific terms of multiple custom taxonomies
- Is get_posts() more efficient than The Loop?
- How to get_posts where ‘menu_order’ is more than 0/zero?
- Display the_content on click jquery
- What is the maximum number of posts a WordPress loop can work with?
- Why only one post (and no pagination) on this variation of the loop?
- Sort posts by most recently modified
- A smarter way to display multiple loops inside a page template
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- Show all posts using the template page and the loop?
- Showing sticky posts with get_posts()
- query_posts() vs get_posts() multiple loops [duplicate]
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- Both a page loop and posts loop on the same page
- Multiple get_posts() queries on one page
- 404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice
- Output meta into arrays
- Get post offset/posts page offset in single post page (outside the loop)
- get_posts() forcing ignore sticky posts on main loop
- loop inside a loop : search for posts in the same category
- php loop error for count posts in category
- numberposts not responding to wp_reset_postdata()
- get_posts and wp_autop (remove filter)
- Need some help with “the_widget()” function
- Is there a way to target only images within the loop?
- Show last post from multiple categories using wp_list_categories
- Question about custom plugin
- How to split a loop into multiple columns
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Cleanest Way to Select Every Second Element in a Loop?
- Get post by page name or slug
- save_post + insert_post = infinite loop
- Are there any scenarios where the query_posts may be used?
- Display subpages under parent page as a list within a loop
- When to use wp_reset_postdata();
- Why do themes have `while( have_posts() )` in templates like single.php?
- What is best way passing variables to theme templates and using them different places like widgets?
- Apply styling only to first page sticky posts
- Related Posts loop – offset
- Too many nested wp_query loops in this hypothetical query?
- pop-up lighbox with AJAX
- Showing current subcategory
- Load comments per post on click with AJAX
- WordPress Loop – Style rows of posts differently
- Generating dynamic Tabs with multiple query post loop
- How do I override part of the main loop in my child theme?
- taxonomy tags 404 to custom post types
- Only display videos and images in the_content() within loop
- Query last updated posts (posts updated in the last 24 hours)
- Publish Categories for a particular Author on a given Post
- How to get the role id from the role name?
- How to hook into container
- Loop inside query
- How can I display other user avatars on an author profile page?
- something strange is happening to my code
- How to modify search.php to not show pages only show posts
- Show articles in Pair
- Randomly display post based on meta value. (Kind of Priority/Weight)
- Make a loop to return x number of posts, but only if they have content or excerpt
- Closing the loop…featured image variable based on post id
- How do you stop the rendering of the website to have something display on the front-end?
- add_action in the loop hooks
- How to render the single post template with the post name?
- static page with multiple loops breaks post pagination
- new custom theme – posts displaying on top of one another
- Offset Loop by 1 , Limit next loop to 1 (Most Recent) Post
- Building a form with WordPress, and also pulling that data for a user page
- How to show multiple attachements together with Scribu’s Posts 2 Posts connector?
- Database query and get_user_meta return incorrect data
- Need to while loop and display contents in the subfield of a group field given by ACF
- How to display a loop of custom post types in columns
- Why my loop is repeat?
- Excerpts not showing on main page
- dispaly all hierarchical post types from a taxonomy
- WordPress Modal showing posts not working properly
- Query posts and display all dates in repeater field in chronological order
- Is it possible to get a post ID of a 2 different custom post types loop embedded in the same post to perform update_post_meta from the frontend?
- Multiple loops in set intervals with code in between
- Loop shows post 5 times in a query
- Attachment Metadata inside of Loop
- Make custom WordPress comments list
- Template included with plugin doesn’t return all posts for custom taxonomy
- Best way to check if a post with specific meta exists
- Default Template infinite loop of Title
- Adding pagination to WP_Query [duplicate]
- Insert/sticky multiple posts in multiple positions
- Transient Loop Not working as expected
- Stuck with conflicting loops on page template
- Change the way wordpress outputs images or image galleries
- Displaying posts on Homepage
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- How to get current page id and compare it to looped pages inside the same page?
- Show amount of posts created today above loop?
- How to create WordPress loop with combination of 4 and 2 columns twitter-bootstrap?
- posts_nav_link() not working on index.php
- How to add custom HTML markup and classes to the_content()?
- Error in Wordprewss loop for page template [closed]
- Tags outside the loop