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
- How to overwrite orderby with add_query_var
- Filter post query to only show direct children of category
- Posts in loop all show the same author when there are many authors
- Exclude recently updated post from custom WP_Query using multiple loops
- Get a list of posts by specific category
- Get author meta data with no published posts in author.php?
- Query for page content, and query for posts on the same page?
- Can’t seem to get an else statement correct? [closed]
- Help with showing text when something is entered in my search bar
- How to write a query-function as a query-shortcode?
- How to show featured post first, then separate loop for other posts
- Output ACF field dynamicaly within a taxonomy loop [closed]
- Print post data inside loop using theme content template
- Show linked products using wp query and woocommerce
- Standard Loop – wp_query
- tax_query not working properly with get_posts
- First post outside of loop, homepage only?
- the_excerpt() not working in custom archive
- How can I display sticky posts at first in wp_query?
- How do I split a large query with a semi-expensive function included into multiple smaller queries
- Custom Wp_query loop takes very long
- Pre_get_post on CPT archive page
- Get posts that were most recently tagged
- SQL query into to WP query
- Prevent WordPress loop from displaying similar post titles
- Custom query for certain post type OR another post type with a certain category
- wp_query order by rand is repeating posts
- Query All Posts: Either Display Most Recent or One with Particular ACF Value Chosen
- A Depth Like Parameter For “get_posts”
- Show number of posts AND number on current page (cannot make it work)
- Use meta query only 3 or more results?
- Search query alteration not working for meta values
- How to get rid of extra Untitled Article in html5 document outline when using new WP_Query?
- Custom WordPress loop, articles not in same order as Array
- Search results stuck on page 1
- Bulk delete comments, foreach loop
- after refresh the id that shows correct in first time click, changes to 1
- Advanced Search – Is this possible?
- Use value from meta key array for use in WP_Query
- Pagination only showed when no category is set in wp_query
- WP_query shortcode inside acf Repeater breaks the repeater loop
- How to get posts that have certain meta key value and order based on another meta key’s value
- Unexpected number of loops in while
- Splitting query results, on the frontend, into separate sections based on meta value without multiple loops?
- Query Multiple Post Types and Paginate Newly Created List
- Filtering custom post type list in admin by custom meta key/value
- How to use meta_query to retrieve posts from multiple custom post type
- Modify WordPress Search
- Block Editor – WordPress 6.1 – CPT Archive Issue – While the title changes in the loop, all records display the same data
- $wp_query->found_posts; returns zero
- How to display only posts from the last day with posts published?
- Rewrite URL custom search query
- posts_per_page showing 16 elements instead of 3
- Loop a Single Taxonomy and Output all Posts Associated (but also show a message for empty ones)
- Optimizing AJAX Query with Large Database
- query loop “inherit query from template” prevents setting sort order
- Post Query with Meta Query no longer working
- Need help with Query Loop. Need to get current taxonomy term and its posts and group them by a different selected taxonomy term
- Run a query for loop ordering by the sum of the inverse of comment age with WP_Query