Try to use WP_Query
instead of using the SQL
. You can get the reference here.
Simple example would be like:
$args = array(
'post_type' => 'my_custom_post_type',
'meta_key' => 'date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'value' => date()
)
)
);
$query = new WP_Query($args);
and use a simple while
loop to iterate through the results.
See this for more info on meta query parameters.
Related Posts:
- Style custom columns in admin panels (especially to adjust column cell widths)
- Counting the number of posts (custom post type) Query problems
- Why are comments and trackbacks still getting through for custom post types?
- Display a query with multiple post types and same relationship on a single page
- How to check if a WP_Query has data
- Why get_next_post_link() or get_previous_post_link() doesn’t return the required links?
- Add metabox with media uploader in a custom post type [duplicate]
- Add Settings to Custom Post Type
- How to set a custom post type post as static front page?
- Add links to post categories and taxonomies in wysiwyg link modal?
- Retrieving 3 latest post from each of 5 different custom post types
- How to save contact form 7 data in Custom Post Types (CPT) [closed]
- Rewrite on custom post type permalink not working?
- Wp-query causing problems with the_content();
- Custom Taxonomy Breadcrumb Navigation
- Remove “-2” from a Toolset Types URL with the same post name
- Make custom post type display as a page
- Problems excluding a custom post-type from the loop
- Get permalink and title by post name?
- get custom post type categories
- Custom query variable – get wordpress to redirect to nice permalink url
- Multiple portfolios with one custom post type?
- Custom Post Type and Taxonomy combination
- How to enable a custom post type to custom user role in WordPress
- How to create an array for a CPT post ID to use in an IF/WHILE statement
- How to filter search results by post type?
- Can’t unregister parent theme’s CPT from my child theme
- Unable to show meta box data in frontend
- Get Post Primary Category
- How to check the terms in single custom post type template
- Custom Post type with ACF in REST API, how do I get those values?
- Loop through Custom Post Type, and then show children within each iteration
- How to only show posts assigned to current user, only in certain post types
- Parent and Child relation for custom post types
- modrewrite not working on my Apache setup
- search also in taxonomy, tags and custom fields
- forming WP_Query for posts of all post types but from specific categories
- Custom Post Types, URL rewrite on multiple CPTs
- How can I get the number of custom post type posts that have a specific attachment image set?
- Bulk Update Custom Fields for Custom Post Types
- Best way to style first post differently?
- Displaying All Posts of a Custom Post Type in WordPress Multisite Backend
- New checkbox in custom post type widget isn’t saving data
- Send notification to the admin when new custom post is submitted
- Adding Page Templates to post but it ignored it
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- CPT Parent as a page and CPT Child as a posts
- Custom Post Type – Duplicate Page Slugs
- WordPress Loop if/else
- Custom post type pagination 404
- List of child custom post types lists all custom post types
- get post types and plugin order
- page template for custom post type
- How to do admin CRUD & Pagination
- Custom Post Type not showing in main loop
- Where are post type columns stored in database?
- posts within custom post type all share the same content in the front-end
- How to change single custom post template by custom taxonomy?
- How to query Posts from a custom post type which contains a custom taxonomy?
- Let users upload image(s) to the post from front end
- Function to allow single post template based on custom taxonomy?
- Multiple custom post types on index page with custom templates
- How set template for “custom post type” individual post
- How do I ensure that post_type and Taxonomy use the same slug?
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Custom Form / Search with Custom Post Type Data
- How to create additional rendering for custom post types?
- How add Filter by Tags and by categories to custom post type in Gutenberg block
- Custom Column in CPT admin table not updated after Quick Edit save
- 404 – Taxonomy Archive Page
- Create and Update 2 CPT sequentially
- How can I display a specific category on Front-Page
- Update user_meta field from post_meta custom field
- Set a template on a custom post in the plugin
- How to seperate posts by categories?
- I want to create pagination for my custom post type archive that i am displaying with loop
- Search in multiple specific post types
- Showing taxonomies with terms that are attached to custom post
- Custom Post Type is not respecting assigned categories
- Saving Child Terms on front end not setting parent
- custom search form for custom post
- How to set a default CPT template and create post attribute´s display rules?
- Custom post url in search.php isn’t the correct rewrited url
- Project Category Heading
- Getting Custom post category from Form
- date archive future posts
- Trying to get custom post type attachment images to function in indexed array
- Loop with Custom Post Type and Taxonomies
- Converting a checkbox filter for custom fields to a dropdown
- Category slug not showing for Custom Post Type
- Custom post type page for authors
- Select custom post by meta value
- Query custom type posts by array of IDs
- Custom post type with custom taxonomy
- custom post-type query just returns two posts
- Custom Post Type Template Based on Page Slug?
- Passing postid of Testimonial Custom Post in Shortcode Parameter
- How to get ‘Products’ on home page?
- body class according to number of published custom posts
- Custom post types not showing in the admin menu on production, but shows locally