I would suggest storing the date-times as either:
- Timestamp (to sort/compare by
meta_value_num
) - ‘yyyy-mm-dd hh:mm (e.g. 2012-04-11 19:37) to sort/compare by
meta_value
Then the following will work (assuming you’re using timestamp):
$now = current_time('timestamp');
$args = array(
'post_type' => 'rides',
'posts_per_page' => 3,
'meta_query' => array(
array(
'key' => 'date',
'value' => $now,
'compare' => '>'
)
)
);
//This breaks pagination!
query_posts($args)
See Codex on WP_Query
.
For bonus points: don’t use query_posts
! (See this). It’s inefficient and requires some extra work to get pagination etc to work.
I suggest you see this (very) related post which shows you how to use the pre_get_posts
hook instead. That post also includes how to sort by your custom ‘date’ field.
Related Posts:
- How to only display posts whose meta_value field is not empty?
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- WP_Query with meta_value LIKE ‘something%’
- Sorting meta_value as integer doesn’t work
- Add a default meta_value to new posts
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- Custom WP Query from meta_value stored as serialised array
- meta_query works locally but not on live server
- Ordering Posts Type A by Custom Fields of related Post Type B
- Custom query for sidebar isn’t returning results
- Need wp_query to return all children and grandchildren
- new WP_Query to get max price meta value not working
- Query multiple meta values
- Why isn’t my `meta_query` array functioning properly?
- How to orderby multiple meta fields if some fields are empty
- Meta_query on same meta key, with diffrenct values
- How to extract specific post
- Meta Query relation “AND” then set array accordingly
- Does meta_value (array) work with ‘orderby’?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- query post by author gender
- Show posts of an advanced search form
- Meta query with compare by more than 2 fields
- Order (by ASC) posts with meta_key so posts without values are last
- Save queried result into database
- WP_Query multiple value not working
- Gather same custom field values in one value in a select tag with wp_query
- Order posts by more than one variable (meta_key and publish date AND time)
- how to query for meta_value have array
- Sorting Posts with meta value not working
- Cannot order by in WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Order by meta values
- Get posts by meta value except one post [closed]
- get_query_var( ‘paged’ ) not working outside of homepage
- get custom post type by tag
- Does tax_query really beats meta_query in all situations?
- Using WP_Query To Get Posts Randomly From today
- How to know which one is the main query?
- WP_Query can’t exclude more than 1 author?
- How to order posts by custom WP role?
- posts2posts query using connected_items array issue [closed]
- Display revision if post status is pending
- Meta query field order together with post_date order causes posts without the meta field to be unordered
- How To Remove/hide some specific categories from two different categories widget from sidebar
- WP Query search for attachments and their exact title
- Excluding Sticky Posts from The Loop and from WP_Query() in WordPress?
- How to display posts month by month?
- Query different number of posts with different formats in one go
- Extending woocommerce admin product search
- Pagination is broken and I need help fixing it
- How to display a posts 1 year ago with custom WP_Query loop?
- Check on which page specific result exist
- Loop returning only 1 result
- Fetch posts that match term slug first two letters (wp query)
- How does one perform a sub query with different post types
- Query with search and subscribers only output
- Query Page Content From Theme Options?
- Taxonomy order exception for specific term
- next_post_link / previous_post_link not working with WP_Query
- How to Create a Random List of Child Pages
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Get all posts with empty meta_value
- Count identical post titles
- get_page meta query not working, maybe a bug?
- Query by date from custom field
- What is wrong with my WP_Query Arguments?
- Query of all pages, including children, ordered by meta key
- specific post is not excluded from the loop
- Unable to paginate a custom page query
- How to WP Query custom multiple custom taxonomies?
- Sort posts using multiple custom fields and menu_order in single query?
- get_the_terms has strange result since version 6.0
- How to display posts from custom post type category(custom Taxonomy) wise?
- How to make WPQuery custom post type work in Twig / Timber
- get_posts return only first result
- How to allow a variable with “/” in wordpress url
- How to get taxonomy image attached to a Post Type WordPress
- How to display a post(by id) along with css in a page?
- update_post_meta performance in a loop woocommerce
- Display posts side by side with custom query
- Is there a way to control both Order By and Order query parameters from one input field
- Custom Order Current Query: By Meta Key and Category
- Search has query that will return no results
- why ignore_sticky_posts in sticky post query
- Select Unique Posts for a List of Tags
- How to modify WP Query to target the first most recent post to adjust content
- Some doubts about how the main query and the custom query works in this custom theme?
- WP_Query always returning the last custom post
- Trying to Exclude Sticky Posts From date_query
- get_posts works but new wp_query doesn’t
- $query conflicting with other queries in the same page
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Query string form $_GET[‘value’] is not working as meta value in wp_query
- query_posts problem – need help
- 294 Queries on Mainpage of WordPress
- Pagination on custom post type not working
- wp_query, calculate with two dates when ‘key’ is text format
- Use value from meta key array for use in WP_Query