Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
29 views

Sort custom post archives by a meta value from a different custom post type?

To make a long story short, I have a custom post type called artworks with these meta fields: title catalog_no artist_key I have a second custom post type called artists with these meta fields: ...
0
votes
0answers
10 views

WooCommerce duplicate refund orders

I've created a query to search for orders based on custom order metadata, which works great! I then echo any data from the order I want to which is fine. However, I have a problem when I refund an ...
0
votes
0answers
29 views

Wordpress Query optimaization for slow query

I've WP installation with some 120K posts. One of the slow queries that frequently appear at @mysql-slow.log is below # Query_time: 1.744827 Lock_time: 0.000567 Rows_sent: 1 Rows_examined: 635732 ...
0
votes
1answer
32 views

WP_Query, ACF field and array

First of all, sorry this title, I really don't know how title the question without write a blobtext! :) Anyway, my problem is this one: I have a custom post "Risorse" (en: Resources). It supports ...
0
votes
1answer
10 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 ...
0
votes
0answers
17 views

Why does my numeric meta query work only on one meta key and not the other?

I have a meta query I'm building as part of a woocommerce product filter. We have two meta queries that can run together or separately depending on what filtering is selected. The intention is to ...
1
vote
0answers
14 views

Meta Query Not Returning Output Despite Having Matching Values

I am formulating a query to pull from a custom post type, with values matching a custom field. The results are blank although I have 3 values set matching the custom field. Is my query formulated ...
0
votes
1answer
35 views

Get posts having meta value between two numbers

have a problem with meta_query_args. <?php $money_form = 0; $money_form = $_POST['search_option_money']; if( $money_form != 0 ){ $meta_query_args = array( array( 'key' ...
0
votes
1answer
23 views

wordpress multiple meta value query is not working

$args = array( 'p' => $product_id, 'post_type' => array( 'product' ), 'post_status' => array( 'publish' ), 'meta_query' ...
0
votes
1answer
27 views

Issues with search after added meta_query

I'm trying to add to the WP search so it includes some meta fields. Here's my current code in the functions.php which was based of another stack from a few years back: function extend_search_query($...
0
votes
1answer
31 views

Strange results from WP_Query

I'm trying to retreive a set of custom posts using the following: // set search conditions $args = array( 'posts_per_page' => -1, 'post_type' => 'fee', 'meta_key' => 'fee_code', ...
0
votes
0answers
23 views

meta_query orderby sort multiple keys

I'm trying to read the birthdays of the users in my database through custom fields that have been added. Displaying the current months is easy but I am trying to capture the current month(remainder) ...
0
votes
1answer
41 views

WP Query Conditionally query meta and taxonomy

I develop a plugin which includes a custom post type that is displayed as a list within WP Admin. There are varying levels of users defined within the plugin and a few other options which determine ...
0
votes
1answer
17 views

Reading Content in an Array as it relates to a meta_query

I am capturing a user's Work Anniversary and their content is being stored in an array. So the key as it relates to these Meta Fields is hire_date and the value that is stored in that array looks ...
0
votes
0answers
28 views

Multiple values for one variable

I have a custom plugin that was written by someone, I can't reach anymore. It has a search option, that produces a table with seminars in different cities. Right now I can have a query with this ...
0
votes
2answers
48 views

Re-order search results with posts_orderby filter and post meta value

I'd like to re-order the search results based on post meta and date . The post meta key is _prioritize_s and the value isn't important. So in a "normal" meta query, I'd just write the compare ...
1
vote
1answer
33 views

Meta Query Filtering not working on Custom Meta Box using Radio Buttons

I have a custom post type called "bids". I'm trying to get the loop to filter posts according to a meta_query. The query should allow for only posts that have the radio button with the value "open" ...
1
vote
1answer
182 views

How to query for custom field within Gutenberg block from outside of that post? [closed]

I created a custom field inside of a custom Gutenberg block (using ACF). It is a Post Object field that accepts multiple post IDs. When inside that post, I can pull the data just fine and everything ...
0
votes
0answers
27 views

pre_get_posts meta_query for dates interval

I have an "activity" custom post type, that has start and end dates introduced via custom fields. I want to add a meta_query argument through pre_get_posts, to get "activity" posts between two dates. ...
0
votes
1answer
21 views

meta query or with meta value

within one of my query_posts I use 'meta_key' => 'clpr_topcoupon', ;meta_value'=> 1, now I would like to show post without as well but the one with meta_value first. I tried: 'meta_query' => ...
0
votes
0answers
18 views

Query nested posts, return if top level post contains a child certain tags

I have posts sorted by two categories ('Chapter' and 'Paragraph"). The 'Paragraph' post can contain several tags. Not custom post types. The 'Chapter' has a relation (via ACF) to the 'Paragraph'. I'...
0
votes
1answer
16 views

How to set meta_query if get_post_meta returns nested array for that key? [duplicate]

I need to get posts with specific post meta. If I inspect regular loop using following code: $args = array( 'post_status' => 'published', 'posts_per_page' => 77, 'post_type' => '...
3
votes
1answer
101 views

Sortable admin column for one meta key with three possible meta values

I've looked over 2 or 3 similar looking threads regarding sortable columns and the meta queries involved with making them work. None seem to resolve my exact problem. I am using the pre_get_posts ...
1
vote
1answer
30 views

Suggestions on making this query/code more performant

I am working on a shortcode that will create and grid of all custom posts of a certain type. This is working all well, if I get only the post titles. However, if I add the post thumbnails, I move from ...
0
votes
0answers
45 views

WP Query to order posts with a specific meta value first

I am trying to write a WP post query to get all posts which have a certain meta key, but with those which have the key set to a specific value to show first. The query modifications are in a ...
0
votes
1answer
26 views

Pre get posts sort by meta key returns no results if meta key does not exist

I am able to sort my posts by a custom field ('tour_length_days'). However if this field does not exist on an existing post then it will return no results. I was hoping there was a way to ...
0
votes
1answer
19 views

meta_query to check all custom fields

I have to use the meta_query argument so that it checks for a keyword in all available custom field values (in array format) saved for the object. The meta keys are different for every object, ...
1
vote
1answer
127 views

WP_Query meta_query >= date

I have been trying for hours, I don't get my query to work: display only posts (from custom post type) with a field (Advanced Custom Fields date picker) value that is more than today. echo date('d-m-...
0
votes
1answer
31 views

Get post by two meta key but order by one of them

i'm using this code for getting posts by two meta keys and order posts by on of them but results not true! and not ordered by post views, please help.tnx $args = array( 'post_type' => '...
0
votes
0answers
60 views

Extend product search with meta in WooCommerce

I would improve the search bar in order to exploit manufacture attribute linked to product. I try to use this to filter product by a custom meta (no product attribute) function custom_search_query( $...
1
vote
0answers
40 views

How does one perform a sub query with different post types

I am creating an application for a home cleaning service using the WP API. I have two custom post types called property and job. The property posts contain a list of home addresses and phone numbers....
0
votes
0answers
25 views

wordpress meta query with multiple meta condition causing a load on server and slows down the server..!

I am writing a meta query with multiple conditions i want to check the conditions one by one it is working fine on the localhost but on the server it is affection and the server slows down and causing ...
1
vote
1answer
54 views

WP_Query with meta_query no results

I have a custom post type and can get them using WP_Query with the following array: $args = array( 'post_type' => 'projects', 'post_status' => 'publish', 'posts_per_page' ...
1
vote
0answers
44 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 ...
0
votes
0answers
6 views

WP meta query: multiple date compares if datepicker is not null

I am trying to build a meta_query which will return all posts that have at least one of their datepicker value greater than today. If the value of the datepicker is null then I don't want to be ...
0
votes
1answer
44 views

Order by Date Custom Field

I'm trying to display a list of upcoming football matches in order of kick off. The code I currently have lists the dates in the correct order but the posts ordering is incorrect. <?php $...
0
votes
1answer
21 views

Custom post types - meta_query: search lesson which starts sooner

I have lesson custom post types which have 4 date sub fields (among others): period_a_start, period_b_start, period_c_start, period_d_start. I want to create a query to get the 8 first lessons that ...
0
votes
1answer
105 views

How to display liked posts of current user in wordpress?

Im using an ajax like dislike post system on my wordpress theme. When the user likes the post there are some post metas to update or to add like the following: if( $post_like == "like" ){ ...
0
votes
2answers
22 views

User meta query results in PHP notice: only variables should be passed by reference

I am using a URL rewrite to put the user's display name in the URL to display a user profile. This part all works fine and the proper value is passed through the query_vars and I can get the correct ...
0
votes
0answers
51 views

Query with multiple CPT but custom field for only one on them

I need the query with merge of two CPT posts (for example cpt1 & cpt2). The problem is when is need to add the 'variable' only for one CPT, that is the a custom field and relevant value (for ...
0
votes
0answers
20 views

How to filter on placeholder image

I'm using the woocommerce-auto-category-thumbnails plugin to replace a blank category thumbnail with a random thumbnail from one of the products in the category (or child categories). It is supposed ...
1
vote
1answer
24 views

WP Meta query for a custom post type based on two values

I'm hoping you can help me out and give me a tip on something I'm trying to achieve and failing miserably. I'm working on a WordPress real-estate theme - Real homes. Here is the link to the website: ...
1
vote
1answer
26 views

How to orderby multiple meta fields with another meta query

I have a custom post type ”events” with meta fields ”startdate” and ”enddate”. Archive query already uses meta query to show only upcoming or ongoing events, but in addition I need to order by both ...
0
votes
0answers
23 views

Sorting with meta_query and multiple, optional meta keys

I'm trying to sort a custom post type by 3 properties: Meta Key: is_featured Meta Key: is_primary Title The two keys are boolean ACF items, and are both optional, so most of the posts don't have the ...
0
votes
1answer
50 views

Mix post date with post meta value using WP_Query

Finding any way to push old posts into the WP_Query using custom fields. For example I have 10 posts in this year, and want to republish 2 posts from the past to custom rss feed. So the posts must ...
0
votes
1answer
49 views

Filtering WP_Query based on wp_postmeta keys values

In the context of a Wordpress widget development, I use WP_Query this way: $args = array( 'post_type' => 'myType', 'post_per_page' => $number, 'showposts' => $number ); $...
0
votes
0answers
12 views

Is it possible to remove a conditional value from WordPress custom metabox

Here I have attached the screenshot from MySQL for easy understanding. In this meta value a: denotes total no of users liked the post. User denotes user with id user-id My question : Is it possible ...
0
votes
0answers
19 views

Post Meta deletion ajax not working

I am trying to remove function in the backend of post like plugin. In the post like plugin they are storing values in the following manner that is User Id , Post id and comment (or) Post . ...
0
votes
0answers
31 views

Is there any way to get all custom posts and all custom terms with it's meta in few queries?

I'm developing a website with a record for me query count. It has 720 Query for the main page. I want to reduce it. The main page structure is like this: ~10 Custom Taxonomy Term Each Term has a ...
0
votes
0answers
21 views

Order by date with more than one meta key in Wordpress query

I have a list of events and they all have either a 'start date' or 'date'. I am trying to list the events in order using either field depending on which is filled out but am having no luck. I tried: $...