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
2answers
21 views

Get category if used in a custom post type

I'm trying to get a list of categories if they are used in a Custom Post type. The post type uses the default categories taxonomy. There are also other custom post types that use the same default WP ...
0
votes
3answers
18 views

Form for search pages by meta datas

Hello I need a form in one wordpress page where an user can search pages by specific meta data. I found how to do search: https://rudrastyh.com/wordpress/meta_query.html#query_meta_values But how ...
0
votes
1answer
24 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
1answer
24 views

WP_Query of custom post type sorted by meta_key has unexpected results

I do not understand why my code outputs the events in a seemingly random order. It's not sorting by the start_time as I would expect. <?php $args = array( 'post_type' => '...
0
votes
0answers
19 views

How to mark only one post as Featured post?

Am working on a blog page and I want to have a featured post as a banner. I have no idea how can I make only one post can be marked as the "Featured" so if another post is marked as "Featured" it ...
0
votes
1answer
19 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 ...
0
votes
1answer
48 views

How to filter posts by specific date and its tag

I want to show the post dates of posts which is greater than $postdate value. what is the wrong with the following code? Instead of filtering the data by dates, it shows all the dates. I do not know ...
1
vote
0answers
51 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' =...
0
votes
0answers
17 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 ...
1
vote
0answers
25 views

Can we return all category (not post) with Custom Query Filter? [closed]

I wanted to make some sort of category grid using elementor's Custom Query Filter. I will have a featured image and and post title. I know ways to do it with a loop but that will be not applicable ...
2
votes
1answer
103 views

Order by two meta keys

I have this code which works fine: $args = array( 'post_type' => 'brands', 'meta_query' => array( array( 'key' => 'br_type', 'value' => 'Aviation' ...
1
vote
0answers
11 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 ...
1
vote
1answer
23 views

Query custom field with date

I have a custom field that has a date picker. This date is in the format 11/12/2019. In my query I have the following: $meta_query = array( array( 'key' => 'date-...
0
votes
1answer
29 views

Show posts from WP Custom Post Type selected from a field in a metabox

Maybe, the question is unclear for you, but I will try to explain. There are two registered custom post types, song and album. I have a metabox on a Create an Album, in which I can select one post ...
0
votes
0answers
32 views

Meta query orderby meta_value_num sorting by role first

I want all of the results to order by meta_value_num, but it's ordering by role first. How do I get them to ignore the role order? Here's my code: $user_query = new WP_User_Query( array( '...
0
votes
0answers
23 views

WP_User_Query Orderby Not Working

If I use the following code, I can retrieve users in the correct order: $user_query = new WP_User_Query( array( 'role__in' => wp_parse_list( $atts['userrole'] ), 'meta_query' => ...
0
votes
1answer
34 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 ...
1
vote
0answers
15 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' =&...
0
votes
2answers
58 views

Wordpress meta query not working

add_action( 'pre_get_posts' , 'my_pre_get_posts' ); Function my_pre_get_posts( $query ) { $value= $_GET['s']; if( $query->is_main_query() && $query->is_search()) { ...
0
votes
1answer
58 views

Why can my filter query SOME metadata but not other metadata?

I'm stumped by what seems like a simple task: I want to randomly select a post that fits certain criteria (metadata set by a specific plugin) and then return that random post to the plugin in question....
0
votes
1answer
19 views

WP meta_query args not working in function

I have three query args for filtering posts in grid. By Author and Status works fine, but ACF meta_query not work. I setup field as select: http://prntscr.com/pi6m66 I need when is selected "Ne" ...
0
votes
0answers
61 views

Get meta_value from GDRating

I am trying to get meta value from GD Rating table for each post ID with following sql: $querystr = "SELECT meta_value FROM $wpdb->gdrts_itemmeta WHERE meta_key LIKE 'stars-rating_rating'"; $...
0
votes
1answer
44 views

Get_term_meta() does not work with pre_get_posts()

I am trying to get custom term meta value for a certain category using get_term_meta() function. This value is stored in the wp_termmeta table. Then, based on that value, I want to modify the main ...
1
vote
1answer
15 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' ...
0
votes
1answer
38 views

How to count items of meta query?

I have manually edited a WordPress WooCommerce hook which hides all out of stock products. The problem is I don't know how to count items found. I tried $query->count but no result. My code: ...
0
votes
1answer
28 views

Check if searched number is within the post meta value

I wrote a function which search a list of properties by specify the number of guests. Each property have a specific number of guests, eg: 10, so if the user search as guests 5 the query should return ...
0
votes
1answer
71 views

Meta query compare for ID's greater than specific ID

I just want to grab all posts that have a greater value than a supplied post ID 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'rid', 'value' => $rid, ...
0
votes
0answers
51 views

WP_Query on meta returns featured posts (not matching meta query)

Migrating a site to wordpress wanted to redirect old urls so I made a function that would catch 404, look for a meta value that would match the number in the url to then redirect. It worked like a ...
0
votes
0answers
20 views

Multiple orderby date arguments

I've had good luck with using multiple orderby arguments in the past, but now that I'm trying it with dates I'm wondering if there's something I'm missing. I'm trying to order some posts by an ACF ...
0
votes
2answers
16 views

Query posts with “non set” meta value

I'd like to make a query of custom posts based on a custom field, say instrument. I need to be able to query only those posts for which the custom field has not been set (i.e. for which the meta value ...
0
votes
0answers
26 views

Add custom fields to search wordpress

I'm using the code below to be able to search using custom fields, which works perfectly but has problems with live search. function cf_search_join( $join ) { global $wpdb; if ( is_search() ) ...
1
vote
0answers
46 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:...
0
votes
0answers
31 views

WP query custom search by meta query nested ACF repetear field Group > Repeater

So I have searched the web but didn't found quite an good solution to this problem. I am having nested ACF field with a repeater inside a group and I want to display and order wp query by that item ...
0
votes
0answers
37 views

Filtering posts by ACF meta query

I am trying to filter posts by a meta_query, based on a post field. The field type is checkbox. The field configuration is: acf_add_local_field_group(array ( 'key' => 'group_5a579h8fs9a98a', ...
0
votes
3answers
129 views

Getting posts by custom field value

I need to get posts with a price less than or equal to for example '1000'. The price is set in an arbitrary custom field. Trying to posts a price that is less than or equal to 1000 $posts = new ...
0
votes
1answer
21 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
0answers
19 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 ...
0
votes
0answers
16 views

Is there any way how to obtain / filter out product variations using WP query by title?

I was wondering if there was a way how to filter product variations by titles using WP query. For example if we wish to delete only certain product variations from all products that are accepted by ...
0
votes
1answer
26 views

User Meta Value not echoing despite Var_Dump Showing correct string

I am going absolutely insane with this one, I cannot for the life of me figure out why I am not receiving the string content. var_dump is outputting the correct result perfectly, yet the content for $...
0
votes
1answer
41 views

Appending to existing WP_Query's meta_query if exists

I'm looking to hook into pre_get_posts to alter WP_Query and put in a condition for the meta_query portion. I want my hook to be non-destructive to any other hook that may have modified this key. ...
0
votes
1answer
73 views

meta_query check for meta value in key which holds an array of values

In every post of my custom post type called "announcements" I save the users' ID inside an array which resides in a meta_key called "post_is_read" whenever a user reads an announcement. Just to ...
3
votes
2answers
192 views

Does tax_query really beats meta_query in all situations?

Let me start saying that I know a 'tax_query' is faster than 'meta_query'. It's always recommended to use taxonomies over custom meta when filtering by custom data is required, but here I found ...
0
votes
0answers
25 views

ACF plugin how to correctly escape $_GET variables before dumping them into a query

I found this code in the Advanced Custom Fields documentation and everything works. My concern is a comment on the original post saying the code was open to SQL injection because it doesn't properly '...
0
votes
0answers
20 views

empty pages on pagination with meta query

I am using meta query to filter posts by various meta tags, showing 9 posts/page, but on pagination there are as many pages as were all the posts displayed without filtering, only that empty pages are ...
0
votes
0answers
17 views

Query Multiple meta key values

I have a custom post type with 4 custom fields Participant (ayp_user) Event (ayp_event) Category (ayp_category) Total Score (ayp_score) I have set the following meta_query in a query. But it is ...
0
votes
0answers
9 views

Posts not showing first to last selected on feature post meta box

i having a problem on my theme.i created a custom meta box to select the post to be featured with a checkbox. in the loop its show the first checked posts,but i want to display just posted and ...
0
votes
0answers
10 views

Grouping Upcoming Events and Past Events custom ACF meta keys

I'm having an issue grouping upcoming events and past events with their own specific headers. A Visual example of this would be: --- Upcoming events ---- event - - event - - event - - event - etc... ...
0
votes
0answers
9 views

Testing for values inside meta_query (sort of like if/else), then evaluating on first one with value

I'm working on a meta_query that filters output of a particular custom post feed (using Beaver Builder). There are two custom meta fields (ACF) that I'm trying to check against in order to perform the ...
0
votes
0answers
22 views

meta_query contains IN array

This is probably not possible... But my experience with wordpress is that "everything" is possible(Just have to find the correct workaround :-) . So I hope someone has a solution for this. I have the ...
0
votes
0answers
16 views

How can I show all posts, even ones that lack the given meta_key, when using orderby in WP_Query?

I have some businesses: +---------------+--------+ | business_name | rating | +---------------+--------+ | McDonald's | 3.9 | | Subway | 4.1 | | Pizza Hut | 4.3 | | TGI Friday'...