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
13 views

Retrieve posts that have a given checkbox value selected with ACF [closed]

I have tried everything, but nothing solves my problem. This is the code I use to retrieve posts that have the selected value in the checkbox: $args['meta_query'] = array( 'relation' => 'OR', ...
user avatar
0 votes
0 answers
15 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 ...
user avatar
0 votes
1 answer
17 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 ...
user avatar
0 votes
0 answers
19 views

Order WP_Query by meta_key priority when 'OR' relation used for multiple meta values

I have a WP_Query that queries posts by an ACF date field AND an ACF true/false field. I am requesting all posts that have a date field value past the current date OR have the true/false field ...
user avatar
  • 426
1 vote
1 answer
16 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 ...
user avatar
0 votes
0 answers
13 views

How to order query results based on if a custom field has been populated, then the order by the date of the post?

I am trying to custom sort a query for product posts (custom content type) based on if a specific ACF custom field for a product ID number has been populated. My client wants to feature products with ...
user avatar
  • 101
0 votes
1 answer
71 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 ...
user avatar
0 votes
0 answers
11 views

Need to check if user has completed a woo commerce payment

I am newbie at php. I am trying to check if user has a payment token or some other value that confirms they have made payment. I want to redirect the page if the payment status is empty 9they have not ...
user avatar
  • 1
0 votes
1 answer
33 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 = "...
user avatar
0 votes
1 answer
33 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/...
user avatar
0 votes
0 answers
13 views

Making WP_Query limit results by date before today where date is a meta_query

We have a custom post type, events. This has a custom field called event_start. In trying to query only past events, I'd like to limit the query with this basic logic: post type is events event_start ...
user avatar
0 votes
1 answer
94 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( ...
user avatar
0 votes
0 answers
33 views

Query ACF relationship field - Comparator IN - Value array

I have two custom post type with a relationship custom field to linked them. I try to do a query based on this custom field using the comparator IN and some IDs in an array, but so far with no success....
user avatar
  • 5
0 votes
0 answers
18 views

WordPress custom search, search by meta key

I have a search form with two dropdowns showing custom terms and two text fields for custom meta keys, The search work with tax_query but meta_query has no result. Here is the pre_get_posts hooks ...
user avatar
0 votes
1 answer
14 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: $...
user avatar
1 vote
0 answers
33 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 ...
user avatar
  • 11
0 votes
0 answers
10 views

I can not display meta value in extras.php and template-tags.php

I have page template that stores reservation input fields, I would like add link to that specific page using meta box but my meta box doesnt work in extras.php and meta-tags.php, I would like to know ...
user avatar
0 votes
0 answers
15 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"...
user avatar
  • 455
0 votes
0 answers
28 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. ...
user avatar
0 votes
0 answers
30 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' ...
user avatar
  • 377
0 votes
0 answers
20 views

How to Ordering by user meta

I am learning WordPress meta query. I am trying to fetch users with asc order of last_name & first_name. My code is like below. if($_POST['orga_id']) { $users_query = array( '...
user avatar
  • 377
0 votes
2 answers
64 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' ...
user avatar
  • 377
0 votes
1 answer
26 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( ...
user avatar
0 votes
1 answer
17 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; $...
user avatar
0 votes
0 answers
14 views

multiple meta_query and orderby question

So I'm trying to sort posts by 2 custom fields. Here is what I have: 'meta_query' => array( 'relation' => 'OR', 'city_order' => array( '...
user avatar
  • 1
0 votes
0 answers
51 views

Filter images from media library by guid meta field

I am using the ajax_query_attachments_args filter attempting to remove certain images from the wordpress media library. They are all in a separate folder within the uploads directory called "...
user avatar
0 votes
1 answer
90 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 ...
user avatar
1 vote
1 answer
17 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 ...
user avatar
0 votes
0 answers
17 views

meta_query / ordered by multiplied meta value [duplicate]

I have created a custom post type which stores a rating value based on an answer provided to a question in a form. So e.g. Item One field 1 - question1_answer1 = 1 field 2 - question1_answer2 = 3 ...
user avatar
  • 1
0 votes
0 answers
38 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? &...
user avatar
0 votes
1 answer
45 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 ...
user avatar
0 votes
1 answer
40 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 ...
user avatar
  • 107
0 votes
0 answers
52 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( ...
user avatar
  • 377
0 votes
2 answers
34 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 '...
user avatar
0 votes
1 answer
66 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 ...
user avatar
0 votes
1 answer
50 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 ...
user avatar
  • 381
0 votes
0 answers
39 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 ...
user avatar
  • 1
1 vote
1 answer
120 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. ...
user avatar
0 votes
1 answer
83 views

How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields

I try to make a sort of fiter for my website. Goal is for the visitors to query results by prices ('prix') and hobbies ('aimerparlapersonne'). Prices are numbers between min and max. Hobbies is ...
user avatar
0 votes
1 answer
38 views

last_name + first_name orderby with meta_query [solved]

I have small issue with orderby. I´m looking solution to orderby ASC (lastname + firstname) example: Selanne Andy Selanne Beeny Selanne Teemu But now it arrays something like this: Selanne Beeny ...
user avatar
  • 3
0 votes
1 answer
188 views

Custom meta_query order for Elementor based on post meta key [closed]

I'm failing at writing an Elementor $meta_query function so posts will be ordered by meta_value_num of a given key. Each post has a numeric value for the key google_unique_page_views My example is ...
user avatar
  • 13
0 votes
1 answer
37 views

meta_query Array

(by using $query->set( 'meta_key', 'start_date' ); or $query->set( 'meta_query', $meta_query_array );) ... how can I send a array of dates in order to wordpress understand that the post as ...
user avatar
  • 23
1 vote
0 answers
37 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 ...
user avatar
  • 297
0 votes
0 answers
40 views

How do i create a custom post query when the meta value is an array?

A number of properties have been imported from an external API and saved into a custom post type called 'Properties'. I want to filter these properties by the city they are located in, however it is ...
user avatar
  • 1
0 votes
0 answers
22 views

Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?

I am using the following query to get past and upcoming events: $post_grid_args['meta_query'] = array( 'relation' => 'OR', // Get upcoming events array( 'key' => 'date', ...
user avatar
0 votes
1 answer
52 views

get_posts query is taking about 40 seconds to execute

I have a meta query in get_posts that's taking a ridiculously long time to complete. It works fine, but it just takes way too long. I have a custom post type named event. On every event post, there is ...
user avatar
  • 268
0 votes
1 answer
25 views

Is this meta query problematic?

I have couple of checkboxes determine the range of min and max people capacity for events. For example: 0 to 100, 100 to 200, and so on. I need to filter them through with a meta query but currently ...
user avatar
0 votes
1 answer
25 views

meta_query compare “=“ returns nothing when it seems it should

Trying to query based on form submission. One select on the form is built with: wp_dropdown_categories( 'name=specialty&taxonomy=specialties&orderby=name&show_option_none=Select a ...
user avatar
  • 1
0 votes
1 answer
21 views

Order resultset by configured value and then list all the rest

I want to list jobs (jobs are custom post types) in country order. The country to prioritise in the resultset is defined by the user in the WP CMS. With the configured country being listed first I ...
user avatar
  • 3
0 votes
1 answer
30 views

How to send variable to wp meta_query value?

I try to to make compare by company title so I need to send this title as variable to meta query value. I use this code and get value = NULL. Please tell me why? $company_name = the_title( ); ...
user avatar
  • 5

1
2 3 4 5
21