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
0answers
12 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
22 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
14 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
54 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
57 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
19 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
13 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
14 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
8 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
9 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
5 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
14 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'...
0
votes
1answer
24 views

Display posts every specific day

i want to display posts every specific day like post should desplay in evry friday with meta key acf date picker <?php $todayName = date('l'); $schedules = new WP_Query(array( ...
0
votes
0answers
15 views

sort posts on front end using url query

I am trying to sort posts on my archive page based off a custom field. The custom field is a number. I have the following in my functions.php file - function wpse139657_orderby(){ if( isset($_GET[...
0
votes
1answer
31 views

Query against multiple locations within single custom post type post

I have a custom post type for "Events" and each event can have a variable amount of "Locations" (lat/lng) which is stored as meta. I need to be able to get "Event" posts based on the bounds of a map. ...
0
votes
1answer
16 views

ACF meta_key and meta_value break loop

I have a CPT with post type of 'recipe'. I have several ACF Advanced Custom Fields in the CPT. My loop WORKS correctly when it is written like this: <?php // args $args = array( 'numberposts'...
0
votes
1answer
11 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
131 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
75 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
13 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
22 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
26 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
153 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
49 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
399 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
21 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
176 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
104 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
33 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
46 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
24 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
21 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
25 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
40 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
137 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
93 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
24 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
16 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
68 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
32 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
32 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
37 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
70 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
22 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
90 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
50 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" ...