Skip to main content

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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
8 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); ...
RafaSashi's user avatar
  • 487
0 votes
0 answers
20 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 ...
Nicole's user avatar
  • 1
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 &...
Sidney Sousa's user avatar
0 votes
1 answer
22 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 ...
Laurence O'Hare-Carroll's user avatar
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 ...
Amal's user avatar
  • 1
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 ...
php-b-grader's user avatar
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 ...
inf3rno's user avatar
  • 135
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 ...
Adam's user avatar
  • 103
0 votes
1 answer
67 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 ...
mtm's user avatar
  • 43
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( ...
Yudi's user avatar
  • 33
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( $...
Jens Draser-Schieb's user avatar
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; $...
apero's user avatar
  • 101
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-...
jakr's user avatar
  • 1
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 ...
Rizal Kholif's user avatar
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 "...
Jillian Hoenig's user avatar
0 votes
0 answers
20 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 ...
chaq's user avatar
  • 1
0 votes
2 answers
26 views

Multiple meta value orderby clauses in a WP_Query

Is there a way to allow for multiple meta value orderby clauses in a WP Query? I have a query which retrieves records between meta keys start/end, and orders them ascending. I’m adding a new key for ...
commadelimited's user avatar
0 votes
1 answer
342 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( ''...
gresch's user avatar
  • 111
0 votes
0 answers
43 views

WP_Query: how to sort all posts by date when one category has a custom "date" field?

We have a couple of hundred posts that are spread across 4 or 5 categories and so far we've been just fine with sorting by publish date. We recently added an "Event" category that has a ...
cmlb's user avatar
  • 1
1 vote
1 answer
40 views

How to compare Event period with Week period using get_posts(), meta_query, relation and compare

I have many posts, each post is an event with a period . This period can be 3 hours, 3 days, 15 days, 3 month. I defined the start time of event with start_timestampevents and the end with ...
imagIne's user avatar
  • 83
0 votes
1 answer
52 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 ...
NW Tech's user avatar
  • 707
0 votes
1 answer
22 views

Query custom fields with three dates - start and end does not work

I have tried to make a reservation system for a book a table in restaurant. But, I have a problem when I try to see/ make new reservations in an specific day - in showing me which table are free at ...
Fujitsu09's user avatar
0 votes
2 answers
62 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 ...
user19103974's user avatar
1 vote
0 answers
44 views

Post Query with Meta Query no longer working

I am working on a magazine website that has a large amount of posts, submissions, etc. There is about 60K+ posts/submissions on the site right now. I don't know when it happened specifically, but ...
Devon Regular's user avatar
0 votes
1 answer
52 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 &...
Mahesh Thorat's user avatar
0 votes
0 answers
244 views

WP Query returning all posts when Meta_query is null

I have a situation here where we have two input fields, one is searching by custom meta fields (ACF) the second is a free search. the client is asking me for results to display in an OR fashion. If ...
post poop zoomies's user avatar
0 votes
1 answer
83 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 ...
Mike Hermary's user avatar
0 votes
0 answers
57 views

Display only posts with thumbnails

I'm trying to have a WP theme display only posts that have a thumbnail. Below is the code of the file that shows some posts on the frontpage. I've already tried to change the code (please see the //...
Johnny Bravo's user avatar
0 votes
0 answers
177 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 ...
Graeme Bryson's user avatar
2 votes
1 answer
708 views

Custom query with custom filtering returning incorrect results

I've setup a custom query, I'm using Woocommerce and I am aware that it has it's own functionality, but have been tasked with creating custom filtering with a traditionally paged product/category ...
Bagseye's user avatar
  • 69
0 votes
1 answer
466 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 ...
Stef's user avatar
  • 103
0 votes
0 answers
28 views

Meta_query question

There is a problem with compiling a request to display posts by meta_query. Need to output posts whose title contains a substring. Can't figure out where I'm wrong. Can someone help? $inputValue = '...
Андрей Кочуров's user avatar
2 votes
1 answer
154 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 ...
Mac Cooper's user avatar
0 votes
1 answer
36 views

Showing Counts on Comment List with Custom Query

I have added a meta value to the comments-meta table that adds a custom 'status' type code (called 'redacted') to a comment. I have used the following code to display a link to display only those ...
Rick Hellewell's user avatar
0 votes
1 answer
43 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(); ...
BN83's user avatar
  • 101
0 votes
1 answer
78 views

Merge meta_value's into a single row and then loop

I have a query where I want to merge values from the wp_users and wp_meta tables, including the meta values of a given meta key. This key could have multiple entries. SELECT u.id, (select ...
Colin's user avatar
  • 113
0 votes
0 answers
115 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 ...
kellymandem's user avatar
0 votes
1 answer
73 views

Shortcode attributes from meta query variables

In the following shortcode, I have two variable, $today and $tommorrow that are being called inside a custom meta query. function display_prognostika_home_loop($atts, $content = null) { // Get all ...
quantum_leap's user avatar
1 vote
1 answer
251 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....
neoswf's user avatar
  • 125
0 votes
1 answer
140 views

WP_Query by meta key not returning any posts

I have set a custom meta key 'post_views' on a custom post type which I can see in my database has been added for 3 posts. I now need to retrieve the ID's for these posts by searching for all posts ...
Dgeorgex000000's user avatar
0 votes
0 answers
72 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 ...
spyfly's user avatar
  • 1
0 votes
0 answers
163 views

Wordpress Meta Query very slow with NOT EXISTS comparison

I need to get posts which do not have a certain meta key. function handle_empty_date_paid($query, $query_vars) { if (!empty($query_vars['not_paid'])) { $query['meta_query'][...
Krzysztof's user avatar
0 votes
1 answer
733 views

What is the meta_query key name for the woo product average rating? [closed]

I am asking about meta_query key name to query the woocommerce all product 5 star average rating in wp_query I have tried to use these names but not working (_wc_average_rating , average_rating, ...
osama B.'s user avatar
0 votes
1 answer
128 views

Meta query with string NOT ending like pattern

I need to find all posts that do NOT have in a specific meta key values ending with ".mp3". I know that I can use REGEXP for this, but I can't figure out how to do it. My code now returns ...
Yuri's user avatar
  • 1,121
0 votes
0 answers
45 views

How do I have multiple metaqueries inside one wordpress query

I have a parent->child relationship between artists and releases. There is another parent->child relationship between releases and versions aka albums, singles, videos, misc. So artist is the ...
DJZEEGLER's user avatar
  • 119
0 votes
1 answer
4k views

How to get all post_id and meta_value using meta_key in wp_postmeta table

The wp_postmeta table has the following columns: meta_id, post_id, meta_key, meta_value I insert post id, meta key and meta_value like: $arrg = array( 'require_login' => 'Yes', 'restrict_by'...
Md. Mehedi Hassan's user avatar
0 votes
0 answers
45 views

Function to Compare CPT Post Custom Value with Default Posts CF Value

I want to create function for compare custom field values of CPT Posts with default posts CF Value. As of now I implemented below code in template file which is working fine, but I want to create ...
Puneet's user avatar
  • 47
0 votes
1 answer
659 views

Get_term with meta_query

I can figure out this query : my purpose is to have a list of taxonomys (category like) with the number posts related to AND from today, ignoring post with a taxonomy's date before today. Something ...
nico's user avatar
  • 25
0 votes
0 answers
50 views

WP query with multiple custom meta not respecting orderby

I have created a wp query to pull a series of posts that have one of three categories (current, upcoming, or past) and I used the multiple custom meta array technique as I want the posts to display in ...
dmkc's user avatar
  • 1
0 votes
0 answers
170 views

ACF meta_query field treated as "0" resulting in false negative search when testing ranges

I'm struggling a bit with building a correct meta_query search. The query in question that fails: if ($data['size']['size_from'] && $data['size']['size_to']) { $args['...
Lindfyrsten's user avatar

1
2 3 4 5
22