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
1 answer
860 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
132 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,131
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
59 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
768 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
173 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
0 votes
1 answer
485 views

Get posts using multiple values from ACF checkbox as meta query wordpress

$args = array( 'posts_per_page' => -1, 'post_type' => 'products', 'meta_query' => array( array( 'key' => 'colors', 'value' =...
goodnight sir's user avatar
2 votes
1 answer
266 views

get_terms_args ordering by meta key not working

I have a custom taxonomy called "edition". Each edition has a meta key "_edition" that stores an incremental number from 1 to N. So, if I have an edition called "Edition 13&...
RBFraphael's user avatar
0 votes
1 answer
346 views

meta_query where the meta value is not the post title

I have a meta_query where I am getting children of a page, I am trying to only get children where the meta key is not the same as the posts title $args = array( 'posts_per_page' => -1, 'parent' ...
Kender's user avatar
  • 133
0 votes
1 answer
502 views

Display posts with specific value first in query

I would like to display posts that have a certain value in a meta field first. I would like to display posts that have a certain value in a meta field first. I have tried it with meta_query and ...
Jonas's user avatar
  • 159
0 votes
1 answer
530 views

Filter posts by meta key

I would like to implement a search function where a user can enter an amount($amount) and based on that argument the search result needs to show all posts where $amount >= loan_min (meta key) AND $...
Ahmad Khan's user avatar
0 votes
0 answers
24 views

meta_query weird behaviour, static int will work, but not user data

I am currently trying to build a Ajax filter for a CPT, all the products have a min and max value of a specific range in which the products works best. Therefore i created ACF groups with a min and ...
AliasElias's user avatar
0 votes
2 answers
386 views

Sort by presence of thumbnail

Looking to ORDER BY the result of WP_Query based on presence of post thumbnail. $query_args = [ 'post_type' => 'custom_project', 'post_status' => 'publish', 'posts_per_page' ...
MikeiLL's user avatar
  • 579
0 votes
2 answers
53 views

Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches

So I have a complex list of ACF repeaters for ingredients, but have a save hook to store them all as one comma delimited text string in a custom field to help. My current "advanced" search ...
gokujou's user avatar
  • 101
0 votes
0 answers
50 views

Search post overlapping dates - meta_query with meta_key

I'm having a search form for rentals that search locations available according to a date range. For now, I store all reserved dates for each posts as post_meta. For exemple ; post_id: 231 post_meta : ...
Daniel Ringuet's user avatar
0 votes
1 answer
467 views

How to properly escape values in meta query

I found this filter some time ago at How to filter my search in post if contains a word in title, content or excerpt? It worked well. But now I am getting an error message of like_escape is ...
John Langlois's user avatar
1 vote
1 answer
36 views

Why isn't my `meta_query` array functioning properly?

I am trying to include a meta_query to only show the 'post_type' => 'want-to-sell-post' that have the key 'key' => '_wpcf_belongs_artist_id',. Right now, all want-to-sell-posts are being ...
DJZEEGLER's user avatar
  • 119
0 votes
0 answers
42 views

Query multiple post types, but different order for each

I have a query which searches 2 post types as below: $args = array( 'post_type' => ['post', 'promotion'], 'posts_per_page' => 12, 'paged' => $...
finlamit's user avatar
0 votes
1 answer
80 views

How using the Meta Box plugin, to filter posts by the value of a post type field?

I'm using the Meta Box plugin to create custom post types and fields. There is a record type teachers, and I'm trying to display the lessons associated with him on the page of a certain teacher. The ...
Alexey's user avatar
  • 1
0 votes
0 answers
59 views

How can I query for posts using a date stored in post-meta?

I’m working on a games release feature for a website I’m building. So far everything is going smooth, but I’m stuck on one area. For the listings on the front end, I want it to look at the “...
M. Straw's user avatar
  • 119
0 votes
1 answer
444 views

How to cache the results of a query and display the cached results

I have a website centered around music. I have 3 main post types- 'Artist', 'Release', and 'Version'. There are 4 types of 'Version'- album, single, video, misc. Artist is parent of Release. (artist ...
DJZEEGLER's user avatar
  • 119
0 votes
1 answer
215 views

How to set up hierarchical relationships without using plugins / meta query

I'm running a large database of musical artists and their releases. I inherited the site after it running for a long time. There are currently several different custom post types, created with a ...
DJZEEGLER's user avatar
  • 119
0 votes
0 answers
240 views

How to add date_query to meta_query array

I am building a meta query array and all fields for the user are optional so some might not have any data. But there is also an option which requires a date query. I am still checking to see if this ...
user8463989's user avatar
0 votes
2 answers
658 views

Order by the first array within a meta_query

I would like to sort the output of my WP Query. I want the events that are coming up soon to be at the beginning. The events that have already taken place should be at the end. So the first array in ...
lcsqntl's user avatar
1 vote
1 answer
787 views

Display post in order of ACF checkbox?

I have a custom post type called ‘Skateboards’. Within the custom post type of ‘Skateboards’ , I added three checkboxes (filed type checkbox) with a field name of ‘skateboard_performance’ associated ...
jonTronics's user avatar
0 votes
1 answer
75 views

order the meta query results by 2 custom fields

I have a custom post type 'brewery', I want to fetch results by 2 custom fields. The desired result is to get all posts with highest review rating (value is in decimal like 4.2 or 4.8) and if few ...
Farhan Ali's user avatar
0 votes
1 answer
114 views

Isn't Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}

I'm trying to count rows in sql table using SELECT COUNT(*) for the post view count. My code is function get_post_views($offset=0, $post_id){ global $wpdb; $get_visit_query = "...
Morty_Smith's user avatar
0 votes
2 answers
1k 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/...
WPswvim's user avatar
0 votes
1 answer
2k views

WP Query ordering on a meta field for posts with a date in the future not ordering by datetime

I have a WP Query: $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'category__in' => $postCategories, 'meta_query' => array( array( ...
TJ Sherrill's user avatar
0 votes
1 answer
24 views

Get other posts sharing the same meta values

I want to get all posts having the same meta values. My Post A has 2 meta values: ID 182 and ID 183 I want to have all post having meta 182 or 183, excepting the current one of course. I have tried: $...
Vincent Decaux's user avatar
1 vote
0 answers
44 views

Overwrite YoastSEO meta-tags with another page's [closed]

I'm writing a custom Wordpress theme and for a specific page I need to overwrite its meta-tags (printed by YoastSEO) with the meta-tags of another page I already know the ID of. I cannot just change ...
cortvi's user avatar
  • 11
0 votes
0 answers
29 views

Creating a query that get all posts but places meta items first

I have a query that gets jobs based on a category. Some of these jobs are "featured" issue is the old system used a "featured" meta key, the new system uses "job_featured"...
dcp3450's user avatar
  • 465
0 votes
0 answers
250 views

Delete all posts with a specific custom field using meta_query

I'm building a listings website using WooCommerce. A listing is either set to live or sold inside of a custom field key status Once a listing is sold then the custom field status is updated with sold. ...
Sven Bjorksan's user avatar
0 votes
0 answers
113 views

Fetch custom post related to a User

I am trying to fetch custom post related to a User. I am using below code. $args = array( 'post_type' => 'tasks', 'meta_query' => array( 'relation' ...
Foysal's user avatar
  • 445
0 votes
2 answers
151 views

Fetch all data of Users

I am trying to fetch users All information by using below code. if($_POST['orga_id']) { $users_query = new WP_User_Query(array( 'meta_query' => array( 'relation' ...
Foysal's user avatar
  • 445
0 votes
1 answer
176 views

Use meta_query in args for relationship

I found this guide and I'm following it: https://rudrastyh.com/wordpress/meta_query.html But I see that it doesn't work for relationship of Advanced Custom Field. Why? This is my code: $args=array( ...
Matteo Feduzi's user avatar
0 votes
1 answer
23 views

How to pull all the contributer users records and order by Designation (which is users meta data)?

I want to show all the contributors by the Designation. Following code is only pull the records and order by ID But I need to data order by Designation: function contributors() { global $wpdb; $...
Manoj Maurya's user avatar
0 votes
1 answer
1k views

ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?

I am looking for a way to query users based on a user meta entry for an advanced custom field which has a given value and itself is from a given layout type. For example, let's say I have the ...
David Wolf's user avatar
1 vote
1 answer
21 views

Display no post when metavalue is 0

There is a page displaying the 3 most popular posts, using the post views on the query. When there are no post views, I don't want to display any posts. How can I display no post when post_views_count ...
Fernando Souza's user avatar
0 votes
0 answers
440 views

Query on meta values and post title

I need some help with my search function. What I want is a search function that search on the post title and on my meta values. The meta values works but how can I add the post title to this query? &...
Liekeee's user avatar
0 votes
1 answer
190 views

ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)

How can I write a WordPress meta query that gives me an array of users/posts that have a given amount of entries in a custom field that stores multiple values? Something like SQL COUNT(), but for the ...
David Wolf's user avatar
0 votes
1 answer
214 views

How do I echo all users' display_name and their meta_value who have a certain meta_key?

I have a meta_key inside the table usermeta called 'sms_subscriber'. The meta_value for it is their phone number. I want to echo a list of all users who have that field; in other words, a list of each ...
Ben Blue's user avatar
  • 117
0 votes
0 answers
73 views

Combine query in WP_User_Query()

I am new user of WP_User_Query(). I don't know how to express whole situation. If I use below code I am getting good result. $users = new WP_User_Query(array( 'meta_query' => array( ...
Foysal's user avatar
  • 445
0 votes
2 answers
102 views

Negative meta_query if storing multiple post_meta values with shared meta_key

WordPress supports storing multiple post meta values for a single post using the same meta key. For example one post can have multiple instances of meta_key 'pet' with meta_value 'cat', 'dog', and/or '...
John Ryan's user avatar
  • 141
1 vote
1 answer
386 views

WP_User_Query ignoring 'meta_query' arguments

So, I'm trying to do a query on 'members' based on some inputs from a form using AJAX. The thing is that when searching for a 'role' I get the expected result. But once I try to look for other meta ...
Marcelo Henriques Cortez's user avatar
0 votes
1 answer
71 views

get posts based on non-single metadata

I have meta data to custom post "event", registered as non-single, i.e., there is an array od metadata "terms" (it is not WordPress term, I just call it term, it is a record ...
Lovor's user avatar
  • 986
0 votes
0 answers
136 views

Multiple nested meta queries

This has been driving me nuts for days so if anyone can provide any sort of solution that would be lifesaving. I have a form that is querying posts (WP_Query), depending on the meta data. Form fields ...
Josh's user avatar
  • 1
1 vote
1 answer
435 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
2
3 4 5
22