As already said, your query arguments are slightly off – meta_query
should be an array of arrays:
$query = new WP_Query( array(
'category_name' => 'events',
'order' => 'DESC',
'orderby' => 'meta_value',
'meta_query' => array(
array(
'key' => 'start_date',
'value' => strtotime( 'today' ),
'compare' => '>=',
'type' => 'UNSIGNED', // Ensure MySQL treats the value as numeric
)
)
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
// Your template code
}
}
Related Posts:
- meta_value_num sort glitch
- Change order of posts
- filter custom field values $min $max
- WP Query – Is this correct?
- Meta_query ‘compare’ => ‘LIKE’ not working?
- Checking if field is set before comparing with meta_query in query_posts?
- Custom query with orderby meta_value of custom field
- Using meta query (‘meta_query’) with a search query (‘s’)
- Using meta_query, how can i filter by a custom field and order by another one?
- Query Posts or Get Posts by custom fields, possible?
- ORDER BY custom field value
- Can I query custom meta data through WP_Query
- Add custom fields to search
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- Matching Serialized Arrays with meta_query
- Meta Query with AND & OR?
- query_posts and only show results if a custom field is not empty
- Filter archive.php by custom meta
- Trying to perform complex custom field query with order by set to field value
- Is there a way to do multiple ordering on a multiple meta_query?
- Order posts by custom field and if custom field is empty return remaining posts
- order by meta_value serialized array
- WordPress Search Custom Meta Field Only
- Compare meta_query decimals not working right
- Ordering posts by anniversary using only day and month
- Calling Specific Pages with wp query Part II
- Loop through two different sets of custom fields
- Query on custom field count?
- Slow meta query with multi meta keys
- Using OR in WP_Query negates the “NOT EXISTS” compare
- How to use query_posts() with a date filter on a custom field?
- How can I query on the year part of a complete date in a custom field?
- How can I combine meta_query queries?
- Displaying posts with only upcoming dates according their custom field date value
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- Display custom post types with custom date field value (before today) & order by custom date field
- Sorting posts by multiple values, combined
- WP_Query display next custom post from today’s date
- Can ordering post list by meta_value cause performance issue?
- Order by value in serialized custom field
- Which is best in the following scenario : post_meta vs custom table vs parent/child posts
- WP_Meta_Query causing long-running MySQL queries
- Author Page Custom Query WHERE author OR [post meta value] OR [post meta value]
- How do I query for a post by custom field?
- meta query not showing any results?
- Sorting posts by custom fields in meta_query
- meta_query for a string inside a meta field containing a comma-separated list
- Order by custom field value not working for acf date field
- how can i use custom field in query post
- using multiple meta_key and meta_value in query_posts
- Complex WP_User_Query call fails on production server
- Query post order by post and desc not working
- How can I sort homepage by a meta value?
- Meta query with timestamp using WP_query
- Orderby custom field meta value ASC and then by date DESC
- Order query by meta_value with multiple custom fields
- How make a custom search on backend in WordPress without plugin?
- How to add a new meta key and assign timestamp to posts
- Show 1 post and after a specific date show the next one
- Get content from pages with same meta_key from Database
- WP 3.1 meta_query for multiple custom field values
- How to select posts from multiple categories and metavalues?
- meta_compare seems to be treating values as strings instead of integers as expected
- Fetch Record based on meta key dates
- How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
- how to make members list directory through wordpress post custom meta key.
- Get posts with same meta value as current post
- Alter main archive, to show posts with meta as last
- Meta Query returns wrong number of posts
- Meta Query And/Or
- Use meta_query to get title of associated post
- Meta query with multiple custom fields for archives page ordering problem
- Ordering posts by custom field named “date” in backend
- query posts custom field calculation value
- Get Data From wp_sitemeta for Multisite network
- Unique meta_key with array value vs repeated meta_key with single values
- get posts where a custom field contains a text
- How can I do a variable for meta_query?
- Query_posts with custom field meta value
- Avoiding ACF get_field and returning to core WordPress function
- Unable to get specific value from post meta
- ORDER BY custom field value out of where clause
- comment meta_query for keys that aren’t yet set
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- change order of images attached to post
- Diamond question mark in text after migrating content
- query_posts with meta_value
- Custom search SQL Query to add custom field in result
- How to put forward a blog post
- tax query between operator like
- How can I change the publish date based on a custom field?
- Best way to sort estates and query them (for rent? yes/no. contains office space? yes/no)?
- Is it possible to compare the current time with a custom “start” and “end date
- Get author total post votes from post meta
- Problem with writting correctly a query posts args in WordPress
- How can I modify my meta_query to work with prices that are stored in the database that contain dollar signs and commas?
- simple fields plugin custom query
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Making WP_Query limit results by date before today where date is a meta_query