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
1answer
7 views

Restrict WordPress search to a single ACF field

I've used the following filter to include an ACF field into my search results. add_filter( 'pre_get_posts', 'so_9224493_adjust_search_query'); function so_9224493_adjust_search_query( $query ) { ...
2
votes
1answer
74 views

WordPress query through Products variation stock [closed]

I have WooCommerce variable products and a filter which is filtering products based on variation attributes. I have variation attribute depth which has numeric value (from 1 to 20) and the filter is ...
0
votes
2answers
44 views

meta query multiple values for the same key

I'm trying to query wordpress with multiple values but it looks like it can't take no more than 4 keywords I'm currently using a loop and I already tried to switch to a IN operator but I need the ...
0
votes
1answer
10 views

How to use germ_terms() with meta_query for ACF Taxonomy field?

I have a custom taxonomy, Events (“event”). Through ACF, this also has a Taxonomy field, “Topic”, linking it to a secondary taxonomy, Topic (“topic”). I want to get_terms() for all Events terms ...
0
votes
1answer
20 views

Unusual high query of user meta data

We have a WordPress installation with many plugins installed. The site is not that highly frequented (maybe 10-20 concurrent users). I know the amount of plugins comes at a cost of performance. ...
0
votes
1answer
25 views

Query string form $_GET['value'] is not working as meta value in wp_query

Here is my code.How strange! if I put any static value replacing $s_string, it's working fine. Thanks in advance for any help. $s_string = !empty($_GET['q']) ? sanitize_text_field($_GET['q']) : ''; $...
2
votes
2answers
67 views

Query WooCommerce orders where meta data does not exist

I'm trying to fetch all my WooCommerce orders where some additional metadata is equal to not empty. $orders = wc_get_orders( array( 'orderby' => 'date', 'order' => 'DESC', '...
2
votes
2answers
48 views

Meta-value query

A little long-winded but trying to explain clearly :) I am delving into the code of my new theme and am not familiar with this type of data storing/pulling - can someone help me understand what is ...
1
vote
1answer
63 views

Filter WooCommerce Orders query with user meta data

I want to list orders from my Woocommerce shop. I have user meta for my users. (unsubscribed) I only want to list the order if that order's user is unsubscribed === 0. I have working code to the ...
1
vote
0answers
18 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 ...
2
votes
2answers
133 views

Meta query interfering with orderby relevance

I'm trying to re-order the search results using the pre_get_posts hook and set the orderby parameter to relevance. I also want to put priority posts, which is based on post meta _prioritize_s to be ...
0
votes
1answer
42 views

Meta Query “IN” doesn't work with ACF checkbox filter

I try to integrate to my CPT archive page some ACF filters. I start with this tutorial : https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/ It works when I use it ...
1
vote
0answers
26 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 ...
0
votes
0answers
26 views

Very slow query generated getting meta data from posts

I need to process some meta_query fields. $meta_query = array( 'relation' => 'OR', [ 'key' => '_sale_price', 'value'...
0
votes
0answers
22 views

WP_Query on custom key and value

I have a posts with a Ymd date custom field. I would like the posts to be able to: Displays the posts where the date is not expired (lower than current date) Displays the posts that have the same ...
0
votes
0answers
17 views

When searching, dashboard query hangs because of “GROUP BY wp_posts.ID”

The problem is that I have a relatively simple post type with two custom fields that need to sort depending on those fields. I have all of this hooked in to pre_get_posts (along with some other sort ...
0
votes
0answers
31 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
20 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
35 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
76 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
57 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
20 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
46 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
27 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
30 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
33 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
24 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
50 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
65 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
41 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
332 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
62 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
22 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
19 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
21 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' => '...
2
votes
1answer
102 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
50 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
31 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
40 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
237 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
33 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' => '...
1
vote
0answers
86 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
47 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
33 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
66 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' ...
2
votes
0answers
50 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 ...