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.

377 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
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 ...
John McGuinnes's user avatar
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 ...
Adnan's user avatar
  • 51
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 ...
P. Sheth's user avatar
3 votes
0 answers
6k views

Custom Upcoming Events List for Events Manager Plugin

I'm using Events Manager plugin. I want to list upcoming events without widget. (2 event with big thumbnail image, after then 4 event with small thumbnail image.) Tried this code: <?phpfunction ...
sakarya's user avatar
  • 222
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 ...
ban-geoengineering's user avatar
3 votes
1 answer
2k views

Very slow query with meta_query on large database

I have a blog with about 200k posts and each one have 20 custom fields. I've been using WordPress Transients_API to cache queries, in the few cases where it can be used, but it can't be used in some ...
quyet's user avatar
  • 65
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 ...
Adam's user avatar
  • 103
2 votes
1 answer
284 views

Meta query field order together with post_date order causes posts without the meta field to be unordered

I've managed to get wordpress to do a descending order on a meta_query field called start_date which is saved in Ymd format in the database by the ACF plugin. However in my query the other post types ...
Carl's user avatar
  • 21
2 votes
0 answers
372 views

Meta query for custom post type ignored in main query

I looked through the interwebz but couldn't find a solution. I am creating a website with custom post types where posts also include custom post meta (through ACF). I am creating an archive file and ...
Kacper G's user avatar
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 ...
kelvin ramirez's user avatar
2 votes
0 answers
84 views

Can an array be used as a meta_query value?

I'm trying to query a custom post type (courses) by grade using WP_Query and Advanced Custom Fields (ACF). Grades (checkboxes) are organized by term (groups). Four grades per term, four terms per ...
Sean Vinci's user avatar
2 votes
0 answers
455 views

How to show recent and upcoming birthdays using meta_query

I have a date of birth user field, I am trying to show recent (past 7 days) and upcoming (next 7 days) birthdays. I have the below but it is not working because the years in the date of births are ...
user1280853's user avatar
2 votes
0 answers
1k views

Using meta_query and tax_query at the same time

I’ve got the following query on my page template: $args = array( 'post_type' => 'givingback', 'post_status' => 'publish', 'posts_per_page' => 100, '...
user6744245's user avatar
2 votes
1 answer
125 views

Which is best in the following scenario : post_meta vs custom table vs parent/child posts

I’m looking for a bit of advice on which way to go with a development question. I’m building a community site where subscribers create their own private posts. The data they enter falls into two ...
Mick R's user avatar
  • 21
2 votes
0 answers
58 views

Multiple meta queries but arrange by specific meta value order

Im working on a function which gets me lawyers based on criteria. The function works fine. Recently I added a meta key called 'is_endorsed'. The value can be either '1' or '0'. I need to bring ...
wp student's user avatar
2 votes
1 answer
155 views

meta_query all posts between to ages

I'm trying to query posts for a specific age range. For example I have a post with an age range from 5 - 10. If I use the following code I get a result when I search for ages >= 5 and 10: $meta_query ...
Marco Becker's user avatar
2 votes
0 answers
46 views

WP_Meta_Query causing long-running MySQL queries

I used the following WP_Meta_Query which queried posts for a specific custom fields pair. $args=array( 'meta_key'=> 'tnid_01', 'meta_value'=>$tnid, '...
Philip's user avatar
  • 103
2 votes
0 answers
825 views

How to make a WP REST API query with meta_query in WP4.7?

There is no "filter" parameter in WP REST API WP 4.7 and this call doesn't work: http://domain.tld/wp-json/wp/v2/cpt_name?meta_query[0][key]=cf_name&meta_query[0][value][0]=cf_value1&...
krusze's user avatar
  • 21
2 votes
0 answers
734 views

sort by date in Advanced Custom Field

I am trying to filter posts with certain values and sort by the date field using ACF module. I have succeeded in filter with package and type. But when i added date sort, its not working. Please help ...
Shyam Krishna Sreekumar's user avatar
2 votes
1 answer
54 views

wordpress custom_meta ordering of timestamps

So I have a wp meta query that is handling the searching of events which have a start timestamp, and an end timestamp, I want to return all results within the two dates a user picks in the search. ...
kisgal21's user avatar
2 votes
1 answer
305 views

XOR functionality for meta_query

I'm trying to resolve the problem with event displaying. An event has its start and end dates, written in meta. For example, event starts on (dmY) 03.04.2013 and ends up on 08.04.2013. Using WP_query ...
Kee Ross's user avatar
2 votes
1 answer
3k views

Order Posts by meta value AND published date

I want to order WP posts by meta key named "sort_date" and if it doesn't exist it should use the post's published date to order posts. Below is the code i am currently using function ...
Ehsan's user avatar
  • 23
2 votes
2 answers
400 views

CPT Meta Searching

I'm developing a WP plugin which uses custom post types and meta data. What I'm trying to achieve is having the meta data searchable. Here is some code that I found which searches the meta data fine, ...
jmutton's user avatar
  • 19
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( $...
Jens Draser-Schieb's user avatar
1 vote
0 answers
39 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
1 vote
1 answer
414 views

Wp_query function to search from product_title 'OR' product tags name

I am looking to show search results from either product title or product tag name. I have implemented the product title search through the below code, but I need to add tag name search also into it. ...
Dhruvbhati's user avatar
1 vote
0 answers
48 views

Fastest way to do meta query when I don't need the actual posts, and just need post_id?

In wordpress I often use $wpdb to just do my queries manually when I just need to extract some value. In my case, I have a Membrepress rule that could be tied to some content type. The rule's meta ...
Brian's user avatar
  • 317
1 vote
1 answer
97 views

meta_query not working on live site

I have the following query_args to fetch events: -> either it's a single event (only start date), so it checks if the start date is between the start of the month AND the end of the month -> or ...
Michael Kroißmayr's user avatar
1 vote
0 answers
66 views

How to orderby multiple meta fields if some fields are empty

I'm trying to orderby meta fields value, but sometimes those values are empty : A > title = 'The apartment', wpcf-f-french-operating-title = ' ', wpcf-f-order-title = 'Apartment' B > title = '...
Wilhem's user avatar
  • 11
1 vote
1 answer
41 views

Fetch Record based on meta key dates

I want to write a query which fetches the data based on my meta key added. Meta key name is 'repeater'. This is my POST META. Serialized: a:3:{i:0;a:3:{s:9:"postdates";s:10:"2021-02-02&...
aliasgar vanak's user avatar
1 vote
0 answers
24 views

How to display multiple custom fields with the same meta_key in an ascending order?

I am using query_posts to display a list of custom fields from some posts on my WordPress site. Each post has at least one custom field called showcase. In some cases, there are two showcase entries. ...
makemassair's user avatar
1 vote
0 answers
364 views

Elementor custom Query with ACF fields to show matching woocommerce products custom fields

I am trying to show custom fields of some products using elementor custom query. The products are coming just fine. But they have usage custom fields matching custom conditions. Have a look at this ...
Joy's user avatar
  • 31
1 vote
0 answers
103 views

How to filter wp_list_categories output with some custom post type meta query?

The main point, why i want to do this, ..is to be able to filter these term listings conditionally, such as: if the CPT that is connected with this taxonomy has some meta fields that are empty or have ...
Viktor Borítás's user avatar
1 vote
0 answers
234 views

Meta_query with multiple keys and multiple values

I have a WP Query code like below to check if have post match all post_meta > get that post, else create new post, but the result always show me a post have only loaicua = cua-chinh and loaiphong = ...
Nguyễn Văn Đức's user avatar
1 vote
0 answers
239 views

WP_Query with meta_query for children

I'm using WooCommerce and it has a lot of plugins to handle different stuff. The one thing needed by the client that no other plugin manages correctly is which variations can be visible for each user ...
ZioCain's user avatar
  • 111
1 vote
0 answers
75 views

How to query post only with different excerpt?

I have this code, im Using ACF PRO to do a reverse relationship <?php /* * Query posts for a relationship value. * This method uses ...
kelvin ramirez's user avatar
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' =&...
user3447788's user avatar
1 vote
0 answers
122 views

Is it a good idea to improve meta query performance by adding tax query?

I'm aware that using taxonomies over metadata is preferred when it comes to posts grouping. In simple words this and this are saying "use meta for unique data and taxonomy for repeating data(the one ...
Vadim C.'s user avatar
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 ...
jakesh_of_redesigned's user avatar
1 vote
1 answer
127 views

How do you get Posts by multiple meta_keys and meta_values with the Rest API V2?

I'm trying to get my Posts by multiple meta_keys and meta_values. How do I accomplish this? The URL should be looking like this: /posts?meta_key=Example&meta_value=Example2&meta_key=Example3&...
nku's user avatar
  • 11
1 vote
1 answer
581 views

Get Current Post ID in functions php, meta query filter

How do I get the Current post ID in functions php when creating an meta query filter? I've made many attempts but all return Null. The filter works as expected when I manually input a number, but I ...
Cory M's user avatar
  • 11
1 vote
0 answers
203 views

meta_query BETWEEN, but the range is stored in the custom field

I've seen plenty of samples of using meta_query to find if the value is between a range, where the range looks something like this: $meta_query_args = [ 'key' => "custom_field", 'value' =...
enrique-ramirez's user avatar
1 vote
0 answers
67 views

Meta_query on same meta key, with diffrenct values

i'm trying to get_users with the meta_query where i need to find users where either they don't have the meta key, or it is blank. It seems like everywhere i look, i should be able to use the OR on ...
bymem's user avatar
  • 11
1 vote
0 answers
24 views

A method for ordering mixed dates in search result loop (theory only, no actual code)

My issue Hello, some time ago: I had the regular post and the custom evento post types; the evento post type had a ev_data_out custom field; the search result loop had to return a list of posts from ...
Marks's user avatar
  • 31
1 vote
0 answers
22 views

How to do WP_Query with two meta fields with orderby clause

The goal is to first try to order by the custom meta field and if its not found then do order by the post date. Here is the query I did so far, but its not working. $args = array( 'post_type' =&...
user8721352's user avatar
1 vote
1 answer
18 views

Stuck in Order by more then one

I want to orderby post by 2 custom fields and alphabetical here is my code 'meta_query' => array( array( 'relation' => 'AND', 'awards' => array( 'key' ...
Hammad's user avatar
  • 41
1 vote
0 answers
391 views

Meta query with regular expression does not work

I am trying to get a meta query with a regular expression to work. I have a custom post type with a custom field "participant-id". The custom field stores a comma-delimited string of user IDs, like:...
Andrei G.'s user avatar
1 vote
0 answers
310 views

Searching in title or meta, with a tax query too!

As suggested in WP Query Args - Title or Meta Value I tried to query my Custom Content Type on Title and Meta Value alternatively. It almost works, but only if I do not introduce a tax query (and I ...
Simone Conti's user avatar
1 vote
0 answers
29 views

Meta query: How do I return posts within a date period from a given month?

I have posts with a meta start_date and a meta end_date, stored in timestamp format (I can change the format if necessary) I would like to return all posts that have a date in that month by giving a ...
DongMaster's user avatar
1 vote
0 answers
255 views

Tax Query for custom Taxonomy field

I have a stock filter on WooCommerce shop page. So I need to filter number of products based on the selection from the user for this filter. I have variable products and I am not able to control ...
wpdd's user avatar
  • 313

1
2 3 4 5
8