Try using meta_query parameter :
add_action('pre_get_posts', 'add_event_date_criteria');
function add_event_date_criteria(&$query)
{
// We only want to filter on "public" pages
// You can add other selections, like here:
// - Only on a term page for our custom taxonomy
if (!is_admin() &&
is_tax('event-tag') || is_tax('event-category')) {
$time = time();
$meta = array(
array(
'key' => 'start_time',
'value' => $time,
'compare' => '>='
)
);
$query->set('meta_query',$meta );
$query->set('meta_key', 'start_time');
$query->set('orderby', 'meta_value_num');
$query->set('order', 'ASC');
}
}
also you need to make sure your meta field start_time
is measured and saved in the number of seconds since the Unix Epoch like time() function.
Related Posts:
- Using pre_get_posts to Filter Posts
- How do I query a custom post type with a custom taxonomy?
- How to show more posts on an archive page?
- Dynamically Create Terms in Taxonomy when Custom Post Type is Published. Almost There!
- how to group custom post type posts by custom taxonomy terms
- Order posts by (hierarchical custom) taxonomy terms and term children
- Posts per Page on custom Taxonomy Template
- How to get the parent’s taxonomy?
- Query posts by custom post type and custom taxonomy
- Limiting number of custom posts shown on taxonomy page
- Include custom post type in “all posts”
- How to get only one category of custom post type?
- Query for posts in 2 taxonomies
- Building an Advanced Search (text, tags, category, custom fields) – Getting the wrong SQL query
- ‘category__and’ for custom taxonomy?
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- How to dynamically build a multiple taxonomy query loop within a post type’s single loop?
- List custom post type by custom tax term as page title
- how can i get posts from custom post type particular taxonomy category
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Query/list all terms and their custom post count
- Archive for custom taxonomy lists all posts instead of current taxonomy
- How to use custom taxonomies to reference complex relationships?
- Displaying custom taxonomy in the admin list of a custom post type
- Query Custom posts of same taxonomy as the post itself
- Conditional Query of Custom Post Type and custom taxonomy
- Show a Category X’s custom post type on Category X archive page?
- How to edit this code to get the categories in achieve page?
- I am trying to hide a custom post type category to logged in users with Pre_Get_Posts
- Listing all term items alphabetically / sorting loop
- How to display Related Posts based on number of taxonomy terms matched
- How to make WP_Query not to show irrelevant posts?
- Custom query – get_the_terms not work
- Control content before and after custom post type loop
- Custom post type, custom taxonomy, query posts only from taxonomy (children of)
- Display custom posts randomly in custom taxonomy archive
- Not able to export large no. of posts in csv
- attach CPT data to a taxonomy
- how to show records that don’t have custom meta value
- Targeting custom post type via functions.php doesn’t work
- List all posts in taxonomy term
- Query Multiple Custom Post Types & Exclude a Taxonomy Term
- Sorting the Loop by Taxonomy Value
- custom post type and a “sticky” position taxonomy
- Posts per Page on custom Taxonomy Template
- List all posts associated under custom taxonomy
- Getting Custom Posts with Custom Taxonomy
- Set different posts_per_page for custom post type/taxonomy
- What’s the most efficient way to get two queries based on an if statement?
- WordPress custom post type
- Display 2nd category, only once, as sub-heading, in the loop
- Using $seed on a custom post type for randomly displayed posts
- Advanced Custom Fields: query posts filtered by multiple field values
- Inserting two categories
- pre_get_posts causes Custom Posts appear under ‘Pages’ menu
- Search for portfolio tags & mixing portfoliotags and post tags
- Display Posts that fit a certain criteria on Category pages
- Get taxonomy name used in a current post
- Need help with Custom Taxonomy + Custom Post Type
- How to properly set the rewrite rules for this case?
- Post Tags not working for Custom Post type
- How to handle this wordpress custom post type rewrite problem?
- Assigning categories to custom post types via a front-end form; only works for native post type
- Custom Post Type with Category Separate
- Displaying all posts by category and showing content on click
- Right way to store a large set of similar information on website? [duplicate]
- In child theme, add CPT to custom taxonomy registered in parent theme
- How to prefix custom post type URL with custom post taxonomy term?
- Define multiple prefixes for custom post type
- How to debug failing updates for custom post type?
- Store a value in global scope after init hook is fired
- Create a post automatically if search result has zero results
- Trying to list years (for a filter) but not all years display
- Custom post categories are not displaying on the page
- custom post type and user post count shortcode
- get_posts wont produce a list of custom type from a given category [duplicate]
- How do I troubleshoot pre_get_posts with Debug Bar?
- How do I Create Single template for custom post type with a custom URL?
- How do you create pillar content pages?
- How to list posts by terms
- Aloha! VERY broad CPT questions. Looking for the theory/best practices behind it
- Changing CPT permalink
- Filter in Custom post type to find the parent post
- Limit custom post type to the authors only on front-end!
- Excluded Custom Taxonomy Term Posts Displaying in loop
- How do I find out which (page) template file my custom child post is looking for?
- URL for archive of custom post type with 2 taxonomy terms
- How to search through all child taxonomies using WP_Query?
- How to order taxonomy terms by most recent post?
- I have a random letter appearing before my content. Where to start looking for the cause?
- List taxonomies by post id
- Custom post type and custom taxonomy key lenght & query performance
- 404 – Taxonomy Archive Page
- Custom taxonomies not displaying in some custom posts
- How to set “section categories”?
- Tags being removed upon updates to related posts: ACF/Genesis/WP5.4.1
- Display Custom Field or Custom Taxonomy in front page /post/product
- Modify default Related Posts Code to Custom Post Type
- Remove custom taxonamy slug with pagination
- Custom taxonomy returns 404 even with saving permalinks