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
1 vote
0 answers
16 views

How can meta values from another site in a multisite be used in a custom query?

Currently, I am using the pre_get_posts action to create a custom query, ordering the posts based on a meta value like so: add_action( 'pre_get_posts', 'my_custom_order' ); function my_custom_order( $...
berlinersueden's user avatar
0 votes
2 answers
39 views

How to get products with the same custom attribute like ean code

I Try to get all products with the same ean code, but the query doesn't work and also doesn't give any errors. What am I missing? Here is the code I use. if (is_product()) { global $product; $...
apero's user avatar
  • 101
0 votes
0 answers
13 views

WP_Query filtering in ACF field containing dates

I'm trying to use WP_Query to filter Advanced Custom Fields posts that can contain this value in the "dates" field (text type), for example "20230101-20230102;20230201-20230202;20230301-...
jakr's user avatar
  • 1
0 votes
0 answers
38 views

How can I filter records in a custom post type list in the admin based on the ACF field in the post that contains the current user?

I have a custom post type called Projects that includes an ACF field named team_members which uses User as a field type and returns a User Array. I want to filter the post type listing so that the ...
Rizal Kholif's user avatar
0 votes
1 answer
16 views

WP Query filtering by custom category not showing all relevant posts

Here's a question I've been trying to solve all day: I added a WP Query that would show posts from a category that the admin chooses with a custom field. The post is a custom post type called "...
Jillian Hoenig's user avatar
0 votes
0 answers
16 views

SQL query based on two different custom field values

I have custom post type "store" that has two different custom fields: Coutry and City. When in the single country page I list all the stores in that country. What I would like to do is to ...
chaq's user avatar
  • 1
0 votes
2 answers
23 views

Multiple meta value orderby clauses in a WP_Query

Is there a way to allow for multiple meta value orderby clauses in a WP Query? I have a query which retrieves records between meta keys start/end, and orders them ascending. I’m adding a new key for ...
commadelimited's user avatar
0 votes
1 answer
145 views

getEntityRecords/useEntityRecords: How to use CPT metadata?

I use getEntityRecords as described in the official data API tutorial (https://learn.wordpress.org/lesson/retrieving-wordpress-data-records/). I.e.: const [searchTerm, setSearchTerm] = useState( ''...
gresch's user avatar
  • 111
0 votes
0 answers
38 views

WP_Query: how to sort all posts by date when one category has a custom "date" field?

We have a couple of hundred posts that are spread across 4 or 5 categories and so far we've been just fine with sorting by publish date. We recently added an "Event" category that has a ...
cmlb's user avatar
  • 1
1 vote
1 answer
31 views

How to compare Event period with Week period using get_posts(), meta_query, relation and compare

I have many posts, each post is an event with a period . This period can be 3 hours, 3 days, 15 days, 3 month. I defined the start time of event with start_timestampevents and the end with ...
imagIne's user avatar
  • 53
0 votes
1 answer
50 views

Complicated `orderby` based on text in custom field

I'm doing a user query and looking to query users that are in a certain department (custom field) -- this works. Now I'm trying to manipulate the order....I'd like to use the meta_key for position and ...
NW Tech's user avatar
  • 717
0 votes
1 answer
19 views

Query custom fields with three dates - start and end does not work

I have tried to make a reservation system for a book a table in restaurant. But, I have a problem when I try to see/ make new reservations in an specific day - in showing me which table are free at ...
Fujitsu09's user avatar
0 votes
0 answers
18 views

wp_query loop how to also display post second time with specific condition

I filtered posts by period : from "current week"* , from * + 1 (following 2nd week), from * + 1 + 2 (following 3rd and 4th week) and from 1st day of current month * 12 month. For the last ...
imagIne's user avatar
  • 53
0 votes
2 answers
38 views

Meta query array - same order as specified order in value

I have a custom Wordpress query that is using an array of product IDs that exist in an ACF field(these IDs do not line up with the Wordpress post IDs). I would like for the order of the returned posts ...
user19103974's user avatar
1 vote
0 answers
35 views

Post Query with Meta Query no longer working

I am working on a magazine website that has a large amount of posts, submissions, etc. There is about 60K+ posts/submissions on the site right now. I don't know when it happened specifically, but ...
Devon Regular's user avatar
0 votes
0 answers
19 views

wp_user_query with meta_value_num for leaderboard

Context : I try to make a custom leaderboard with the WP_USERS_QUERY class and the custom code below. I use the gamipress plugin for points system. The leaderboard works fine, displaying correctly the ...
Megayamori's user avatar
0 votes
1 answer
48 views

WordPress - Optimize the Meta Query for 3 meta keys at a time

Records in post_meta as follow: post_id key value 1 price 10 1 price_to 5000 2 price_type 'POA' 3 price 12000 3 price_to 17000 4 price 1200 4 price_to 8000 5 price_type 'POA' Code Snippet &...
Mahesh Thorat's user avatar
0 votes
0 answers
32 views

How making a new search box in admin post table working on a specific column

Presently I have already set a function that let me filter the ID column in the admin post table. It works with the exact "match", if I write 8198 or 8175 i get the apartment (post) with ...
Andrea Sacconi's user avatar
0 votes
0 answers
146 views

WP Query returning all posts when Meta_query is null

I have a situation here where we have two input fields, one is searching by custom meta fields (ACF) the second is a free search. the client is asking me for results to display in an OR fashion. If ...
post poop zoomies's user avatar
0 votes
0 answers
20 views

Meta Query compare with LIKE pulls similar post types: 55 and 155, and 1,155

In my admin I have a CPT called Artists, and another one named Exhibits. I connect exhibits to artists via a relationship field in the exhibition cpt. I setup a query on the artist page to pull the ...
TechyDude's user avatar
  • 125
0 votes
1 answer
53 views

Order custom post type by posts with most likes first

I am using the Like/Dislike plugin on a custom post type and am trying to order the display of posts by the most like count down to those that have no likes (and no set meta value in the posts meta ...
Mike Hermary's user avatar
0 votes
0 answers
56 views

Display only posts with thumbnails

I'm trying to have a WP theme display only posts that have a thumbnail. Below is the code of the file that shows some posts on the frontpage. I've already tried to change the code (please see the //...
Johnny Bravo's user avatar
0 votes
0 answers
154 views

Use value from meta key array for use in WP_Query

I have a CPT named 'Physicians', and have assigned an ACF field named locations to that post type — locations is an ACF post object field. I also have a 'Locations' CPT and intend on displaying the ...
Graeme Bryson's user avatar
2 votes
1 answer
532 views

Custom query with custom filtering returning incorrect results

I've setup a custom query, I'm using Woocommerce and I am aware that it has it's own functionality, but have been tasked with creating custom filtering with a traditionally paged product/category ...
Bagseye's user avatar
  • 69
0 votes
1 answer
283 views

Problem with custom WordPress Rest API search route with query parameters

I'm building a search component in a ReactJs application sitting on top of a headless WordPress CMS and I've run into a problem which I can't seem to fix. It might be that I'm doing something ...
Stef's user avatar
  • 103
0 votes
0 answers
26 views

Meta_query question

There is a problem with compiling a request to display posts by meta_query. Need to output posts whose title contains a substring. Can't figure out where I'm wrong. Can someone help? $inputValue = '...
Андрей Кочуров's user avatar
2 votes
1 answer
103 views

Custom taxonomy with custom meta value is not sorting correctly (query returns the same value for orderby regardless of sort column click)

I have a weight class category, where I want to sort by weight so Heavyweight shows at the top, and Flyweight at the bottom. I have created a custom meta field called 'weight' where I store an int ...
Mac Cooper's user avatar
0 votes
1 answer
32 views

Showing Counts on Comment List with Custom Query

I have added a meta value to the comments-meta table that adds a custom 'status' type code (called 'redacted') to a comment. I have used the following code to display a link to display only those ...
Rick Hellewell's user avatar
0 votes
1 answer
36 views

Use meta query only 3 or more results?

Using elementor I'm currently running the following: add_action( 'elementor/query/model-query', function( $query ) { $meta_query = $query->get( 'meta_query' ); $meta_query = array(); ...
BN83's user avatar
  • 101
0 votes
1 answer
62 views

Merge meta_value's into a single row and then loop

I have a query where I want to merge values from the wp_users and wp_meta tables, including the meta values of a given meta key. This key could have multiple entries. SELECT u.id, (select ...
Colin's user avatar
  • 113
0 votes
0 answers
104 views

Is it possible to customize meta query in this way?

I have a custom post type called promotions. In each promotions' post meta, I store two fields, promo_start_date and promo_end_date. The idea is to only show promotions on the frontend, where the ...
kellymandem's user avatar
0 votes
1 answer
71 views

Shortcode attributes from meta query variables

In the following shortcode, I have two variable, $today and $tommorrow that are being called inside a custom meta query. function display_prognostika_home_loop($atts, $content = null) { // Get all ...
quantum_leap's user avatar
1 vote
1 answer
181 views

get_post_meta bringing back results, but $wpdb->postmeta doesn't

I'm trying to discover if post exists, based on post_title & metadata post_language. Until now, the best way I discovered, was using methods appearing in posts like this one, this one, or this one....
neoswf's user avatar
  • 125
0 votes
1 answer
122 views

WP_Query by meta key not returning any posts

I have set a custom meta key 'post_views' on a custom post type which I can see in my database has been added for 3 posts. I now need to retrieve the ID's for these posts by searching for all posts ...
Dgeorgex000000's user avatar
0 votes
0 answers
62 views

Hook to filter based on form value and insert term

I am working on a form where I am trying to insert a term to a taxonomy. So I have a drop down select with a list of my taxonomies and then the next field is a simple text field where the users will ...
spyfly's user avatar
  • 1
0 votes
0 answers
140 views

Wordpress Meta Query very slow with NOT EXISTS comparison

I need to get posts which do not have a certain meta key. function handle_empty_date_paid($query, $query_vars) { if (!empty($query_vars['not_paid'])) { $query['meta_query'][...
Krzysztof's user avatar
0 votes
1 answer
613 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
110 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,111
0 votes
0 answers
42 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
3k 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
36 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
518 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
48 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
161 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
308 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
161 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
268 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
427 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
269 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

1
2 3 4 5
21