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
1 answer
26 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
  • 45
0 votes
1 answer
46 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
17 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
12 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
  • 45
0 votes
2 answers
22 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
27 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
16 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
41 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
24 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
76 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
19 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
38 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
53 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
70 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
249 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
130 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
56 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
0 answers
83 views

Ordering WP_Query results by second meta_key

I've got code that currently returns results of a query based on a meta_query (whether or note the current date is past a stored key "ex_closing_date" - or has no closing date at all. The ...
Adam Hourigan's user avatar
0 votes
1 answer
30 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
29 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
0 answers
78 views

acf/save_post affecting WP_Query results

I have CPT Events, which lists from WP_Query and orders by meta query where events that have date/time less then current are not shown + ordered by most closest events to further. Array ( [...
bruno's user avatar
  • 1
0 votes
1 answer
34 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
79 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
62 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
143 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
92 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
33 views

'Active lotteries' only custom query for woocommerce lottery plugin and elementor

I am wanting to create a custom query that returns only active lottery products on my lottery 'style' website. I have been given a query but I am not sure where this query should be placed in my ...
bhoff92's user avatar
0 votes
0 answers
46 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
119 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
0 answers
260 views

Using 'meta_query' with the 'pre_get_posts()' hook disables searching for post titles

I tried using only the pre_get_posts() hook to add some custom fields to the default posts search. But it didn't work. With the code below, excepting the last code line, neither titles, nor content, ...
Yurié's user avatar
  • 1,101
0 votes
0 answers
307 views

WordPress extremely slow when using get_posts with multiple meta_query relations

I am having an issue with this query. Do I have it written incorrectly? This is on WP 6.0.2 and PHP 7.4.30. $now = current_time( 'Y-m-d H:i:s' ); // Fetch all upcoming bookings and events. $posts = ...
PthPndr's user avatar
  • 43
0 votes
1 answer
368 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
0 answers
31 views

Order Wp Query by earliest of 3 dates meta query

I need to order CPT by the earliest of one of three potential dates. The caveat - not all posts have values for all the dates. My current semi-working query has been created by reading lots of Stack ...
Sean Doherty's user avatar
0 votes
1 answer
73 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,101
0 votes
0 answers
40 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
2k 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
32 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
  • 37
0 votes
1 answer
362 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
43 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
142 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
251 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
122 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
199 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
341 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
159 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
0 votes
2 answers
222 views

Sort by presence of thumbnail

Looking to ORDER BY the result of WP_Query based on presence of post thumbnail. $query_args = [ 'post_type' => 'custom_project', 'post_status' => 'publish', 'posts_per_page' ...
MikeiLL's user avatar
  • 559
0 votes
2 answers
46 views

Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches

So I have a complex list of ACF repeaters for ingredients, but have a save hook to store them all as one comma delimited text string in a custom field to help. My current "advanced" search ...
gokujou's user avatar
  • 101
0 votes
0 answers
43 views

Search post overlapping dates - meta_query with meta_key

I'm having a search form for rentals that search locations available according to a date range. For now, I store all reserved dates for each posts as post_meta. For exemple ; post_id: 231 post_meta : ...
Daniel Ringuet's user avatar

1
2 3 4 5
21