I needed to get post with type event and the custom field “date” later than today, this sample of code worked perfectly for me, I hope it helps to someone in a similar situation.
$today = date("Y-m-d");
$today1 = date("Ymd", strtotime("$today"));
$custom_meta = array(
array(
'key' => 'data_de_inicio',
'value'=>$today1,
'compare'=>'>',
'type'=>'date',
),
);
$query = new WP_Query(array(
'post_type'=>'event',
'showposts'=>'3',
'orderby'=>'meta_value',
'meta_key'=>'data_de_inicio',
'order'=>'asc',
'meta_query'=>$custom_meta,
)
);
Related Posts:
- meta_query dates from an array
- Return only Count from a wp_query request?
- WP_Query vs get_posts
- Usage of the new “posts_clauses” filter in WordPress 3.1?
- WP_Query: query posts by ids from array?
- pre_get_posts with get_posts
- Query Custom Meta Value with Increment
- Identify which loop you are hooking into; primary or secondary?
- SQL query equivalent to WP User Query
- Transient pagination not working properly
- How to speed up wp_query, took more 5s to run against 100k posts
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- Undefined WP_Query::has_posts()?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- if/else on custom query gives 200 OK when condition not met?
- How to find exact match for search term in WP_Query? What is the additional string added in LIKE query in WP_Query?
- Order by summing multiple values
- Order by empty custom field
- Check if loop has any categories?
- How to get list of posts from permalinks?
- Is_single() conditional tag returns null in query
- Transient api Caches confused
- Include current post into loop
- Should I reset $wp_query?
- How to filter query loop block with a search string from the query parameters
- Update query for wp_posts and wp_postmeta
- mysql query order by
- I am officially missing something about transient posts
- Woocommerce Get Orders By Meta Value
- WP_Query & Duplicate entries
- how to show more than 1 post into three columns query
- Ordering Posts by parent category, name ascending
- WP_Query always returning the last custom post
- WP_Query secondary query failing
- Loop through multiple custom fields with increasing number
- Get a list of the last posts grouped by author and filtered by category
- Parsing External Table Arguments
- WordPress query very slow on +/- 300k DB entries and 7 INNER JOIN
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Resetting post data to previous loop in nested loops
- Should we trust the post globals?
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Make loop display posts by alphabetical order
- get custom post type by tag
- Group posts by custom field
- How to get the posts published in last two days using WP_Query?
- get_posts() seemingly ignoring post_type
- Can not switch the queried post in pre_get_posts hook
- Pass the same object to multiple widgets in a template with one query
- Why execute the_post()?
- What is considered a default query for the request filter?
- $wpdb insert is not work
- Using WP_Query and WP_Meta_Query Outside of WordPress
- Improve wp query perfomance on large db
- How to query a custom post type with a taxonomy filter but display post type archive page?
- How to display 7 most recent days of posts?
- Create A Loop With A Variable Number of Posts For Each Bootstrap Row?
- Change query_posts to WP_Query in page but does not work
- Optional Meta Query
- Set conditional on template based on referring page slug
- Filter posts in category archive page by year using a dropdown
- Show post number in widget loop
- Search form not working with custom query?
- Include data from custom table in WP_Query
- date_query seems to be ignored by wp_query
- Better wordpress attachment query than this
- How do I rewrite this loop as a new WP_Query style-loop?
- Is it possible to query from external database? [duplicate]
- Can’t sort custom post type by random
- Exclude taxonomy term from all loops, but having it on widget
- How to set up hierarchical relationships without using plugins / meta query
- Meta query compare for ID’s greater than specific ID
- Ordering posts by custom field and grouped by month
- relation OR instead of AND – Filtered term ID’s in loop
- Performance concerns: index.php vs taxonomy-$taxonomy.php
- Why does apply_filters behave different inside and outside a loop?
- meta_query where the meta value is not the post title
- Multi-layered WP_Query
- `offset` WP_Query argument dont work via `pre_get_posts`
- Function the_posts_pagination() not compatible with WP_Query arguments
- SQL query injection with fifu image
- Pagination of custom page with custom fields query
- How to show specify category template for both parent and child category
- Pagination inside the blog page not working
- WordPress Query optimaization for slow query
- Custom Query Pagination not working on static front page
- Meta query doesn’t remove placeholder escape before query
- Query doesn’t display text data with apostrophes
- query all posts published by certain user id
- modifying the loop multiple times with arguments passed through ajax to wp_query
- WP_Query causing links to not work
- How to get query results for the next page
- Iterate through ID’s in loop
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- Pull Instagram images into an existing loop?
- Multiple loop for “featured” items returns wrong posts
- First post outside of loop, homepage only?