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
- Multiple queries and pagination
- Query multiple custom post types in single loop
- Wp get all the sub pages of the parent using wp query
- Use REGEXP in WP_Query meta_query key
- Show posts without term
- Show two random posts from custom post type
- Add the “active” class only to the first loop item in a WordPress query [closed]
- Get posts by meta data OR title
- Duplicate Queries
- Loop inside the loop
- How to count post type that has a particular term?
- Group posts by meta_key
- How to query ‘posts_per_page’ to display a different blog posts index template?
- WordPress custom archive page
- Retrieve or Query Pages by ID
- Show all parents and children in custom post type in right order
- Why is this coming back as null? Thats wrong. There is one post
- WordPress Query is taking more then 20 second and stuck on creating index
- Get the Plugin Which Triggered a MySql Query in WordPress?
- How to retrieve current page WP_Query arguments?
- How to limit WP_Query to one result on the loop?
- How to correctly pass values to wpdb->prepare()?
- Setting get_queried_object
- How to use offset in WP_Query
- difference between like ‘%%%var%%’ and ‘%var%’
- Create WP_Query to search for posts by their categories or their parent/child categories
- Multiple loops without repeating content
- Sort query by author: 1 author, then others
- How to orderby multiple meta fields if some fields are empty
- Filtering posts from different categories into different section by doing WP_Query only once
- How to list posts with disabled/closed comments, with pagination?
- How to make a second query offset -2 from current post
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- WP Query – order posts by meta field first and then order the rest
- Wp_query with 2 meta keys and array of meta values
- Create a loop on my pages with new “WP_Query”
- WP ForLoop to compare meta information of posts to determine what post to display
- How to SQL query posts IDs by categories AND authors?
- Search.php – return number of results but cannot loop through
- Creating ‘posts page’ loop based on the page itself
- Query multiple post types, but different order for each
- Custom wp_query inside a conditional stament inside a template part doesn’t work: why?
- Check the stored / cached WP_Query with transients on post change
- New template file does not load category-specific post
- use mysql variable in a $wpdb->query to reindex a column?
- Fix wp_term_relationships slow query in get_posts
- Query post with content only
- How to get_comments() ordered by date and parent?
- Query postmeta based on meta_value, return array of post_id
- Why is my query not giving results?
- Fetch only categorized posts
- Continue loop after $queryObject
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- loop through custom post types with meta data
- Using Query In Post Type Archives
- Showing posts from 4 categories along with all latest posts
- the_excerpt() not working in custom archive
- SQL query into to WP query
- Search results stuck on page 1
- Use value from meta key array for use in WP_Query