Turns out meta_query
was the way to go. This is the code I used to make it work.
add_action( 'pre_get_posts', 'filter_posts' );
function filter_posts( $query ) {
$now = date("Y-m-d H:i", strtotime('+2 hours'));
if( is_category() && !is_admin() && $query->is_main_query() ) {
$query->set( 'posts_per_page','10' );
$query->set( 'orderby','meta_value_num' );
$query->set( 'meta_key','date-start-custom' );
$query->set( 'meta_query', array(
array(
'key' => 'date-start-custom',
'compare' => '>=',
'value' => $now,
'type' => 'DATE'
)
));
$query->set( 'order','ASC' );
}
return $query;
}
Related Posts:
- How to show posts rank based on custom field value
- Get current taxonomy and display query accordingly
- Trying to exclude custom posts based on date, while sorting by custom field
- Need to display a Jan 1st post as the site’s front page on Jan 1st, and Jan 2nd post as front page on Jan 2nd etc
- Extracting a TLD from the content and assign to custom field
- Apply the_title() filter in post & page title, but not in menu title
- Update post counts (published, draft, unattached) in admin interface
- Update all posts automatically when using post_meta
- Add custom field to all posts in specific category
- Exclude category on blog list page
- How to remove_filter that filters iframes in posts? [duplicate]
- meta_box or custom_field as a second tinymce post-instance?
- Create A Metabox For A Custom Field
- Should ‘setup_postdata()’ be reset with ‘wp_reset_postdata()’?
- Sanitizing `wp_editor();` Values for Database, Edit, and Display
- wp_enqueue_media() slows down my WP site
- How can I get all posts data from within a paginated search result?
- If specific user role then sticky post
- How to add a custom field after wp post
- Custom fields on a virtual page
- Query posts from different categories in multisite
- Sorting posts according to view counts not working
- What Is meta_id In wp_postmeta?
- Get a custom field of all posts on current blog page
- the_posts filter been called multiple time
- How can I get a post field value using javascript?
- Automatic value for custom fields for posts
- Improving WP_Query for performance when random posts are ordered
- Filter Custom Post Type by Category with Ajax
- Ajax posts filter by date, comments, top views, top likes
- How to add Tags Filter in wordpress admin dashboard
- how to remove dash (-) post status from post title on posts listing page wordpress
- Get latest posts from WordPress site without header, menu and sidebar
- do_shortcode within post query
- How can I sort posts by the date and a custom meta field?
- Most liked page not displaying posts
- Query get post,how to add comment box
- How to hide html tags on revision comparison pages?
- Ajax post filters not working
- Display Meta Values in Custom Filter – Admin Custom Posts
- Automatically add custom fields value to wordpress post
- More then one menu items are assigned with “current-menu-item” class
- How can I setup a relationship using categories in WordPress?
- How i can limit period of post publication?
- Redirect to another page using contact form 7? [closed]
- Exclude current custom post on single post
- First x post with another template then the others
- Why Query is returning empty array?
- Delete all drafts?
- Wrap every month posts in div
- meta_value timestamp older than now
- post__in not working with pre_get_posts, but post__not_in does work
- Query for first 3 posts to change the look and feel
- Query posts and filter at query time by value of custom meta
- Very complex post query
- Change the default blog post post attribute template name from “default template” to something else
- Delete post revisions only for a single post
- Is it possible to add a shortcode below post title?
- Display post by click on the link
- Queries take 120+ seconds on my large WordPress site
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- How to display only one category in a custom post type?
- Why my meta boxes won’t show in front post page?
- Anyone know a php snippet for showing the first 200 characters of the most recent post?
- How to query posts by month based on date custom field?
- Will multiple category descriptions effect my search engine optimization?
- Automate post update for all posts?
- Display custom post front end filter by ACF equals current user
- Only the most recent post is showing on my category page (working on localhost, not live site)
- Show only posts with titles/permalinks that do not contain certain words
- Filter posts by month (dropdown)
- Query to fetch custom taxonomy along with post title
- How to fetch courses in all languages in WordPress?
- How to add a block to a category page?
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- Add id attribute to h1 element of wordpress post
- filter posts based on menu_order
- Show 5 posts and than 3 posts offset with pagination
- How to delete all posts with dead image urls?
- Querying posts from current category, using a variable as array argument
- Query posts from newest category
- Auto populate custom fields by post date
- ACF Relationship – Get Parent’s Post Object
- wp query custom orderby not custom field
- How to retrieve a post by inputing the url in a custom field and displaying it on an options page
- Query post by meta key of another table
- Custom fields in normal posts
- Query post category & remove any post id
- Ordering posts alphabetically by meta keys and title
- Why I have this strange behavior when I try to exlude the featured post from posts visualization?
- How to modify specific parts of a post content in WordPress
- Grab next post title in archive page
- Continuous listing from a custom field
- How to store post rating system data post independent?
- get_post_meta property of non object
- How to limit post query to only return a total count of items with certain post statuses?
- How to make a local “scroll to ID” on post?
- Display posts with id equal to relationship value
- Read more opens attachment
- Sort Posts Alphabetically Based on Specific Category (Divi)