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
- Categories list into registration form
- Add a custom meta box in the post options that loads some html code in the header
- How can I setup a relationship using categories in WordPress?
- Exclude the first ‘n’ number of posts of a tag from home page?
- Query Posts With Over 1000 Views
- How to allow visitors to filter posts by multiple taxonomies
- Cannot retrieve a custom RSS field from posts
- posts_per_page option limits the number of Gallery items
- How i can limit period of post publication?
- Hooking into the post editing screen for an existing page only
- Query Posts by Custom Field
- How to setup a query to output posts by groups of five?
- Redirect to another page using contact form 7? [closed]
- Trying to alter the post_content through the_post
- Exclude current custom post on single post
- Dynamically switch template on click
- How to get posts and comments amount per hour, per year and per month?
- add to end of post in the loop with plugin
- Get all custom post types excepted some…
- How to rate a post from Admin Side / Manually?
- Add filter to the end of the post
- Get all comments of author’s posts
- First x post with another template then the others
- Why Query is returning empty array?
- Delete all drafts?
- Get post content with all filters applied, knowing post id
- Customize rel=canonical tag for single blog post
- How to I retrieve the ID from the Posts page?
- Wrap every month posts in div
- Adding bootstrap classes to video shortcodes
- Is it possible to filter the main loop to exclude posts from a specific category?
- Inner join overrides Advanced Custom Fields plugin’s get_field [closed]
- meta_value timestamp older than now
- Counter is skipping post when I still want it visible [closed]
- Get post ID from a link
- Do not show children of a category
- query post limits
- post__in not working with pre_get_posts, but post__not_in does work
- Create a list of posts with topic headdings
- Add field to user meta table in database when link is clicked
- Hide custom metabox value from custom fields
- Can’t get full post title if there a spaces in title
- How to get all post_parents of a post?
- Get post meta retrieving wrong value
- Query for first 3 posts to change the look and feel
- Why posts array is empty?
- Query posts and filter at query time by value of custom meta
- Run query_posts if SESSION is empty?
- Modify posts listing at back end
- Edit multiple custom post types while saving a new or edited post
- Filtering posts on Post Administration Page by Week Number instead of by Month
- Prevent posts with certain post_meta to be edited
- 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
- Hook for changing excerpt content when excerpt not set
- if in category but only with post meta
- Is it possible to add a shortcode below post title?
- Post filtering is returning blank page
- How to give classname to post if post has no content?
- Display post by click on the link
- Output Post with ACF Fields into other Post
- Saving Post Data in Another Database
- Queries take 120+ seconds on my large WordPress site
- Exclude some posts from displaying in wp_query based on some condition
- Updating permalink structure using ‘post_link’ filter results in 404 error for posts
- How include css class based on post ( in loop ) slug?
- Related Posts function not working
- How to retrieve certain number of images from a wordpress post?
- Add two custom fields as a default to the “new post” page.
- Restrict displaying posts to the poster itself (in Back-end)
- After ajax image is outside the “ tag
- Edit custom fields in posts list
- Add multiple meta keys to a post at once
- WP_Query custom field pass the post id
- How to convert query sql to shortcode in wordpress?
- WordPress loop not working on static front page
- Exists filter or action that change Add New Post link?
- Some doubts about how the loop work (trying debugging it)
- If custom field is empty, use one from a previous post
- saving/reading custom field value does not work – no value gets POSTed
- How to display only one category in a custom post type?
- Why my meta boxes won’t show in front post page?
- Adding external field to my post form (admin side) and to post show (frontend side)
- Adjust the order for returned posts
- Export all posts to import as product items
- get last post’s link with SQL query
- changing parent_id on post
- Trim posts from WP-Query?
- wp_list_categories() Exclude All Categories Except One
- How To Use Custom Fields With .mp3 Links
- how can display a post on home screen without images
- Custom Select Query – Selecting the Year?
- Anyone know a php snippet for showing the first 200 characters of the most recent post?
- Display content between two dates?