Refer to the Codex page for setup_postdata()
:
Important: You must make use of the global $post variable to pass the post details into this function, otherwise functions like the_title() don’t work properly…
Also note that you can use WP_Query
to do these queries, rather than writing raw SQL.
Related Posts:
- modify all posts of a category to “no comments allowed”
- Deleting Custom Post type data using mySQL command
- wpdb custom post_type problem
- $wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
- Insert post metadata for all posts in CPT at once if metadata no existent
- Convert simple SQL Query to WordPress query
- Why doesnt my tag page populate with this custom post type?
- Create a WordPress Database query to find users who purchased specific product through WooCommerce [closed]
- Is there a way to have the view link on manage posts page to open in a new window or tab?
- Getting rid of /my_custom_post_type/ in the single view URL
- Custom post type menu missing after 3.0b2 -> 3.1.2 upgrade
- Custom Post Type – List all attachments on Edit Screen
- Group posts by custom post type
- Custom Page that comes with preloaded content for the user
- How inefficient is it to use a Custom Post for 4-5 sentences & pull all to 1 page?
- How to check post type (to include custom css)
- How to customize a permalink (URL) structure?
- Plugin: register custom post types, child ready and performance best practices
- Display only one post each WEEK
- Add meta value to custom post type on publish
- convert custom query to wp_query
- How to Mass Delete Images from Media Library
- using $wpdb to get custom post type with term
- Permalink structure by Post Meta value
- How to integrate video slide using custom post types?
- Converting the_content string to an array?
- A question on creating filters for custom posts using taxonomy
- Conditional Query of Custom Post Type and custom taxonomy
- will post_id ever change? Can I safely use post_id for custom queries?
- List custom taxonomy specific to one custom post type
- Define new user capability for custom post types?
- How to allow visitors to enter custom post type?
- Is it possible to create relational metabox values in a custom post?
- Custom Post Type Query for Sidebar Doesn’t Work on Front Page
- Meta query for custom post type ignored in main query
- 2 Templates 1 custom post type according url
- How do I move/order posts with a tag to the end?
- changing meta value and meta key of price field
- Display custom fields from custom posts in RSS feed
- WordPress sort search results by custom order
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Hide parent categories when clicked, and show it’s childs
- Custom Path/Folder behind a custom post type
- Time based access control of custom post types – what is good approach?
- Show titles, date of all posts on single category page
- delete_published_posts does not work
- How to start a new post with custom Taxonomies already set?
- WooCommerce sort products by the actual product width(not the shipping width)
- Create a custom php page and load it at a specific slug
- Structure of data : CPT + terms
- How to handle paged param in post and custom-post-type?
- Default text in a specific post type, but not visible?
- Update postmeta Parent when post_status child change
- WP_Query custom post type query not showing the exact post type
- Assign External Database Queries to Global Variables and Make Them Accessible
- How to import a custom MySQL DB table into a WordPress custom post type
- Shortcode to display Staff post type based on Location post type and Specialty post type
- How to remove post listing page for a custom post type
- How to include term custom meta into the custom taxonomy term permalink structure
- Get terms that contain posts that in turn belong to other terms?
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Function causing the loop display posting more (empty)
- A form that can save/edit after first input
- Adding the_content() in custom template email
- Cannot save CPT meta box
- non-hierarchical post type with hierarchical url structure
- Send notification to the admin when new custom post is submitted
- How do i search authors from search form using author’s name
- Allow users to create posts without logging in?
- How to add attributes to taxonomies that may be different from post to post?
- Pages are not saving due to custom post type
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- wpdb custom tables without plugin
- Migrating a taxonomy’s tags to the native category
- wp_insert_post sometimes fails after API call
- How to produce a sub-page-system in WordPress
- Best structure / rewrite rules to achieve the following url
- don’t publish custom post type post if a meta data field isn’t valid
- How does order=asc effect a wp_query (its acting pretty weird in a loop)
- Save custom post type to external database
- How to sort posts in a custom post type by title in ascending order by default?
- Categorise Custom Post Types
- $post not working working in AJAX plugin with custom post type
- Proper way to display latest 5 posts grouped by post type?
- Detect inside a custom query the kind of post type to assign custom classes
- custom post type vs. conditionally displaying meta boxes for specific terms?
- Edit the_content() function so to add a div wrapper
- How do you make a custom post type items automatically delete items 3 months after publication?
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Number of posts in the archive
- custom post data – how to
- Ordering Submenu Pages in WP 3.1
- 404 Error on form submission within custom post type
- Custom URL redirect in WP
- Remove Quick edit for custom post type?
- Replace dynamically content in a custom database table when a custom post is created
- How to customize work area / admin area in a custom post type without plugins?
- How can I have different content for different countries?
- Change “empty trash” button text?
- WPDB for post count on post