Questions tagged [meta-query]
Refers to a mechanism built into the WP_Query class for querying the database for post data, including pages and CPTs, based upon post meta data.
1,058 questions
0
votes
0
answers
37
views
How to adjust meta value to UTC time in WP Query
I'm displaying three lists of events on my site: past events, current events, and future events. The lists are sorted by a custom date time field. The code I have is currently working, but Wordpress ...
0
votes
1
answer
33
views
Query 'orderby' when there are multiple values for the same meta_key
I'm trying to create a custom sortable admin column for a custom post type that contains a "repeater" field. The plugin I'm using for this field saves the values as separate entries in the ...
1
vote
1
answer
49
views
Select posts using @wordpress/data with query based on custom field always returns all records
I am trying to select records that have a custom field value that matches a search condition but the result is always all records
To register the custom field for my post type I am using the following ...
1
vote
0
answers
52
views
Display posts in correct month order using single date custom field
I have developed a WP Query that displays posts from a custom post type and taxonomy, and orders them by date using a custom field.
The posts have a single Advanced Custom Fields date picker field ...
1
vote
1
answer
38
views
Sort posts based on an acf field called fecha value return longtext '20240517'
I have a field called acf date for certain posts and I need to sort these posts by this field, but the value comes in this format: '20240517' and I need to sort the posts in ascending order with this ...
0
votes
0
answers
33
views
Meta query sort order is lexigraphical instead of numeric
I'm working with lumber and have custom post types with ACF fields for height and width in decimals.
I'm trying to sort my posts first by height and then by width. I am using the following code:
// ...
0
votes
0
answers
186
views
Admin products page column not sorting
I import products to my woocommerce site, and all the imported products have an category called "external".
Note: All the external products have a "_ei_product" meta key with an &...
0
votes
2
answers
176
views
How to use meta_query to retrieve posts from multiple custom post type
I am having two custom post type "meet_our_community" and "news"
I have added a checkbox field named 'add_to_meet_our_community' from the acf to 'news' post type.
Now I when tried ...
0
votes
1
answer
63
views
Is there a way to use MySQL JSON functions in meta queries?
There are JSON functions: https://dev.mysql.com/doc/refman/8.3/en/json-search-functions.html can be used to search in complex data with MySQL. In the case of meta keys and values it is an issue that ...
0
votes
1
answer
146
views
Passing a variable containing a comma separated list of values in a meta-query
My objective here is to collect a series of values from a custom repeater field into a comma separated list so they can be used in a meta query. The first part of this is operational, and I think ...
1
vote
0
answers
44
views
How can meta values from another site in a multisite be used in a custom query?
Currently, I am using the pre_get_posts action to create a custom query, ordering the posts based on a meta value like so:
add_action( 'pre_get_posts', 'my_custom_order' );
function my_custom_order( $...
0
votes
0
answers
89
views
How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?
I have a custom post type called Projects that includes an ACF field named team_members which uses User as a field type and returns a User Array. I want to filter the post type listing so that the ...
0
votes
0
answers
32
views
SQL query based on two different custom field values
I have custom post type "store" that has two different custom fields: Coutry and City. When in the single country page I list all the stores in that country.
What I would like to do is to ...
0
votes
1
answer
652
views
getEntityRecords/useEntityRecords: How to use CPT metadata?
I use getEntityRecords as described in the official data API tutorial (https://learn.wordpress.org/lesson/retrieving-wordpress-data-records/).
I.e.:
const [searchTerm, setSearchTerm] = useState( ''...
0
votes
1
answer
73
views
Complicated `orderby` based on text in custom field
I'm doing a user query and looking to query users that are in a certain department (custom field) -- this works. Now I'm trying to manipulate the order....I'd like to use the meta_key for position and ...
0
votes
2
answers
112
views
Meta query array - same order as specified order in value
I have a custom Wordpress query that is using an array of product IDs that exist in an ACF field(these IDs do not line up with the Wordpress post IDs). I would like for the order of the returned posts ...
0
votes
1
answer
75
views
WordPress - Optimize the Meta Query for 3 meta keys at a time
Records in post_meta as follow:
post_id
key
value
1
price
10
1
price_to
5000
2
price_type
'POA'
3
price
12000
3
price_to
17000
4
price
1200
4
price_to
8000
5
price_type
'POA'
Code Snippet
<?php
$...
1
vote
1
answer
134
views
Order custom post type by posts with most likes first
I am using the Like/Dislike plugin on a custom post type and am trying to order the display of posts by the most like count down to those that have no likes (and no set meta value in the posts meta ...
0
votes
0
answers
212
views
Use value from meta key array for use in WP_Query
I have a CPT named 'Physicians', and have assigned an ACF field named locations to that post type — locations is an ACF post object field.
I also have a 'Locations' CPT and intend on displaying the ...
0
votes
1
answer
760
views
Problem with custom WordPress Rest API search route with query parameters
I'm building a search component in a ReactJs application sitting on top of a headless WordPress CMS and I've run into a problem which I can't seem to fix. It might be that I'm doing something ...
2
votes
1
answer
222
views
Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)
I have a weight class category, where I want to sort by weight so Heavyweight shows at the top, and Flyweight at the bottom. I have created a custom meta field called 'weight' where I store an int ...
0
votes
1
answer
77
views
Use meta query only 3 or more results?
Using elementor I'm currently running the following:
add_action( 'elementor/query/model-query', function( $query ) {
$meta_query = $query->get( 'meta_query' );
$meta_query = array();
...
0
votes
0
answers
173
views
Is it possible to customize meta query in this way?
I have a custom post type called promotions.
In each promotions' post meta, I store two fields, promo_start_date and promo_end_date.
The idea is to only show promotions on the frontend, where the
...
1
vote
1
answer
357
views
get_post_meta bringing back results, but $wpdb->postmeta doesn't
I'm trying to discover if post exists, based on post_title & metadata post_language.
Until now, the best way I discovered, was using methods appearing in posts like this one, this one, or this one....
0
votes
0
answers
93
views
Hook to filter based on form value and insert term
I am working on a form where I am trying to insert a term to a taxonomy. So I have a drop down select with a list of my taxonomies and then the next field is a simple text field where the users will ...