Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
1 vote
1 answer
2k views

Get posts with multiple meta values

I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array(...
0 votes
1 answer
1k views

Woocommerce products search with custom fields

i have a woocommerce e-shop website. My search is searching only in product title, short description and SKU fields. I want to search also in some custom fields (like "_barcode" and "...
1 vote
1 answer
2k views

Filtering variable WooCommerce products by stock level using meta_query

I'm trying to filter the products on my shop page based on stock level by adding a condition to the meta query. For variable products I get zero results, but simple products work. I'm running the ...
0 votes
2 answers
25 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 ...
3 votes
1 answer
901 views

How to count data records in wordpress which have same meta_value in wp_postmeta table?

I want to get number or count of same meta_value of meta_key == 'parent_id'.How can i get it? What should be the wordpress query for counting records in same table? //set the meta_key to the ...
0 votes
1 answer
1k views

WordPress Meta Query Null Values Order

I have a custom WP_Query to sort some events by two meta fields - date and time. $args = array( 'post_type' => 'event', 'posts_per_page' => 10, 'meta_query' => array( '...
0 votes
1 answer
19 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
763 views

Not able to get my custom search result using meta_query and tax_query together?

I created a custom search where i am able to show the Fields (ACF fields) and also Taxonomies. But while I am searching by taking the combination of both Taxonomies and meta fields, i am not getting ...
0 votes
2 answers
2k views

How to create frontend Post filter using meta query

I have created a post filter like the image below, but I have an issue with selecting multiple values from different fields. All the fields in the filter are custom fields. The thing is, in the admin ...
0 votes
1 answer
25 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
1k views

shortcode order for event custom post type

ok im working on a website using post type event with post_meta event_start_date, i created a shortcode and everything is displaying fine except for it displaying in order, it seems as its not ...
1 vote
1 answer
2k views

meta_query in WP_Query value is not accepting array

I'm trying to pass an array of values into a meta_query value. // Works as expected to return posts with 1474 in featured 'meta_query' => array( array( 'key' =&...
0 votes
2 answers
776 views

Extending WP Query: Custom geolocation meta values work, but tax_query breaks

I've built a custom query for geolocation searches. I'm saving lat and lng within each custom post type as a meta value. My query extension returns results successfully when lat and lng are the only ...
4 votes
1 answer
3k views

WP_Query min and max values

I'm building a houses class and I want to filter these houses with a query. But don't get any results: Example house: Min price: 10 Max price (field not required): empty I've a price filter ...
3 votes
2 answers
8k views

How to create/modfiy WP_Query to search in post title OR custom field?

I need to modify or create a WP_Query that will search for a search term in both the post title OR a custom field (called 'my_field'). I have been reading and trying for hours, but I am right back to ...
0 votes
1 answer
813 views

Unable to gather Image URL from Custom Post Type's; Custom Meta Field

I have wrote a very basic plug-in, it creates a Custom Post Type (CPT) that has multiple custom meta fields. I cannot seem to echo out the Image URL. I have tried a heck of a lot of other similar ...
0 votes
1 answer
1k views

Use WP_query to match post types based on custom field values

i'm trying to query posts from the post type Product that match with the current post in the loop from the post type Item, based on the custom fields product-ean and item-ean. For example: i have a ...
1 vote
1 answer
2k views

Meta query with order by another custom field

Edit: I will try to explain in detail my problem. I am working on a portfolio site. There are a few custom post types: Projects, Publications, Exhibitions, Lectures, and Slides. The home page consists ...
1 vote
2 answers
2k views

WP User Query fails when searching meta queries and search columns

I'm building an advanced User search using WP_User_Query but experiencing some unusual behaviour. I'm trying to search with a term that I know exists in the user_nicename and user_email fields but ...
0 votes
1 answer
2k views

Get unique post by meta value using wp_query

I use wp_query to retrieve my posts by using a meta value. One of the meta values have the same text stored in the database. Let me give an example. Post title Meta value hello1 text1 hello2 ...
0 votes
2 answers
799 views

Selecting posts older than the current Unix epoch timestamp

I am trying to perform the following query, which originates by the fact the post's 'date' and 'time' are entered as separate custom fields. $args = array( 'post_type' => 'some_kind_of_posts'...
2 votes
0 answers
15 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 ...
1 vote
1 answer
2k views

how to make URL link query string

I have pages with a custom meta field called "ctr_state", and it contains a state name, like "Arizona". I am trying to construct a hyperlink that will return an archive-like list of pages that match ...
0 votes
1 answer
968 views

How to sort WooCommerce products page by latest in-stock items first?

How to sort the WooCommerce products page by latest in-stock items first and all the out-of-stock items to the last? Currently, I'm using a code snippet from "https://www.businessbloomer.com/...
2 votes
1 answer
2k views

ACF repeater field with meta_query

How can I use a repeater field with meta_query I have a repeater field with some text values only and have a form that sends variables to a page where I get the value and storage a value which is the ...
0 votes
1 answer
26 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
912 views

How to create better WP_Query to look for date time which is anywhere between two meta values?

The following arguments are used for WP_Query to check if a reservation for a game can be created. Meta input fields for post are created using ACF DateTime Picker and set to Y-m-d H:i:s $start_date =...
1 vote
1 answer
2k views

How to create a meta_query to get all posts with a specific meta data?

Here are the args for my query : $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' =>...
0 votes
2 answers
2k views

How to use germ_terms() with meta_query for ACF Taxonomy field?

I have a custom taxonomy, Events (“event”). Through ACF, this also has a Taxonomy field, “Topic”, linking it to a secondary taxonomy, Topic (“topic”). I want to get_terms() for all Events terms ...
0 votes
2 answers
1k views

Conditional posts in WP_query for search

I have a custom post type that im trying to limit results in search. The CPT is a deal/coupon, with a start and end date for each of the deals. What I'm trying to do is only show these posts in ...
0 votes
1 answer
25 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( ...
0 votes
1 answer
1k views

How to get an archive page meta?

Im trying to get some meta from the plugin Yoast Seo, set to a archive page of a custom post-type. What am I doing wrong? $titleSEO = get_post_meta( '_yoast_wpseo_metadesc', true);
0 votes
1 answer
2k views

Wordpress meta query with meta serialized data array value

Looking for a method to nest AND/OR relation in meta_query based on array serialized values. Reviewed these already: Query multiple meta key values? WP Meta Query for some meta (array) values I ...
3 votes
1 answer
1k views

Working Bootstrap Carousel Conversion to WP - Technical Questions

I have coded a working Bootstrap carousel, it needs to be converted to WP. It's a small chunk of the site, but as a Wordpress newbie, am stuck in understanding the technical issue. So here's what I ...
0 votes
1 answer
831 views

Search using specific meta fields only (excluding post title and content)

I have a custom post type my_cpt with 9 custom meta fields like first_name, last_name, location, phone, email etc along with post title and post content. Now what I want is to search using first_name ...
0 votes
1 answer
3k views

Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check ...
1 vote
2 answers
1k views

meta_query 'compare' => '!=' not working

I am using a custom post-type, in post there are a checkbox meta field for featured post. So there are two scenarios. First with featured posts Second with non featured When I called featured posts ...
1 vote
0 answers
18 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
1 answer
1k views

Filter result of Custom Post Type using meta_query with ACF

Im using a custom post type named property to list some houses and flats. In this cpt, I have multiple custom fields from Advanced Custom Fields plugin, such as localization, price, rooms and so on. ...
0 votes
2 answers
3k views

meta query multiple values for the same key

I'm trying to query wordpress with multiple values but it looks like it can't take no more than 4 keywords I'm currently using a loop and I already tried to switch to a IN operator but I need the ...
0 votes
2 answers
47 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
39 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
18 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
1 answer
18 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 "...
0 votes
1 answer
672 views

Attachment Metadata inside of Loop

Basically, I'm trying to call attachment info to display withing a loop, for use in an image gallery. I know I need to use wp_prepare_attachment_for_js($attachment_id) but I can't seem to get anything ...
0 votes
2 answers
25 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 ...
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 ...
0 votes
1 answer
271 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( ''...
51 votes
14 answers
80k views

meta_query with meta values as serialize arrays

I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in ...
0 votes
0 answers
40 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 ...

1
2 3 4 5
21