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,052
questions
0
votes
0
answers
2
views
WP_User_Query get_count issue with meta_query relation
I'm using WP_User_Query to count the total number of users based on specific criteria. Generally, the following code works well:
$args = [/* your arguments here */];
$query = new WP_User_Query($args);
...
0
votes
0
answers
18
views
meta_query post_date not returning results
I'm working on a query where I have a few conditions, one of them involving post_date. However, whenever I try to write my query, post_date doesn't return any matches. If I comment that part out, it ...
0
votes
0
answers
19
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
1
answer
21
views
WP Query: orderby with one meta key, but multiple values
I'm trying to order a wp_query using one custom field. It is a radio group with three values: G, S and B (These represent Gold, Silver and Basic). I've been following the documentation and have looked ...
0
votes
2
answers
49
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
26
views
WP_Query not using relation key as expected and not producing any results
I have created a custom post type service-provider with custom taxonomies region and service-category - By itself, this search works as expected BUT I want to also search on an ACF field.
I have an ...
0
votes
1
answer
31
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 ...
2
votes
0
answers
18
views
get_meta_sql hook is not firing
WP_Query uses WP_Meta_Query. I thought this calls the WP_Meta_Query::get_sql() to define the meta query SQL which is where the get_meta_sql filter is applied.
I can't get the get_meta_sql filter to ...
0
votes
1
answer
59
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 ...
0
votes
1
answer
27
views
Order posts base on last favorite post by user
How can I order favorite posts based on the last post favorited by a user? Currently favorite posts appear based on post date.
$favorites = get_user_favorites();
$favorites_query = new WP_Query(array(
...
1
vote
0
answers
19
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
2
answers
53
views
How to get products with the same custom attribute like ean code
I Try to get all products with the same ean code, but the query doesn't work and also doesn't give any errors. What am I missing?
Here is the code I use.
if (is_product()) {
global $product;
$...
0
votes
0
answers
23
views
WP_Query filtering in ACF field containing dates
I'm trying to use WP_Query to filter Advanced Custom Fields posts that can contain this value in the "dates" field (text type), for example "20230101-20230102;20230201-20230202;20230301-...
0
votes
0
answers
43
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
1
answer
19
views
WP Query filtering by custom category not showing all relevant posts
Here's a question I've been trying to solve all day:
I added a WP Query that would show posts from a category that the admin chooses with a custom field. The post is a custom post type called "...