Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
21 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
18 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
4 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
29 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
13 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
27 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
0answers
15 views

get_users() and custom meta_query with SQL procedure

I'm writing a WordPress plugin with a users listing. To build this users listing, I use the get_users() WordPress function which work perfectly. I built a form to select some options to find users ...
0
votes
2answers
9 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
40 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
16 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
20 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
19 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
14 views

Get posts argument meta query

I'm trying to get some Custom Post Type data thanks to get_posts. I need to get the CTP where the date (added by an ACF input) is before a date. I have this : $posts = get_posts(array( '...
0
votes
0answers
18 views

WP_Query: compare multiple values with serialized data in database

I am using WP_Query and I need to compare multiple dates with a meta_key named data_evento, containing multiple dates as well. If at least one date is matched, corresponding posts should be returned. ...
0
votes
0answers
15 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
0answers
21 views

WPquery mulitple sort orderby

I have a post_type with multiple dates and would like to sort it a certain way - but after way too long on this simple task, I'm still stuck :) How I want it to sort: Every post with a Date2 set, ...
0
votes
1answer
35 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
32 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
17 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
13 views

Query Custom Post Type by Custom Field ID

I'm not sure if i've just been staring at this too long. To give some general info, I am trying to query custom post types based off another CPT's custom fields. Let me explain. I have a custom post ...
0
votes
0answers
22 views

WP_Query to Fetch Products Order-By Custom Product Attribute

I have created one Custom Product Attribute named "published-year" which gets stored in table "wp_postmeta" => "meta_key(_product_attributes)" => "meta_value". I want to fetch all Products Order-By ...
0
votes
0answers
20 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: $...
0
votes
0answers
14 views

WP_Query with meta_query with two clause and Search&Filter Pro

I have custom post type job, which has one custom field chceckbox named top_job and it has only one choice Top job. There will be always only one Top job. I need to display this one top job always on ...
0
votes
0answers
35 views

Why does this incorrect pre_get_posts meta_query work for sort order?

I've got a fairly complicated post type archive page that I need to order by two meta fields and the post title. To do that, I'm using pre_get_posts with a meta_query that simply tests for the ...
0
votes
0answers
66 views

WP Query. Ordering posts by another post types meta

I have a custom post type called BID which contains a users bid (similar to freelancer.com, upwork, etc) However I need the BID results on the page to be ordered by meta stored in a users profile, ...
0
votes
0answers
13 views

Adding query parameter filter to REST endpoint by custom database table

I am adding a query parameter to a CPT reviews REST endpoint of an ACF custom field value with the following: http://mywebsite.local/wp-json/wp/v2/reviews/?rv_type=video Now here comes the issue. I ...
0
votes
0answers
26 views

Meta_Query with multi select values

I have the following: $int_args = array( 'post_type' => 'intervention', 'meta_query' => array( array( 'key' => '...
0
votes
0answers
15 views

How to combine search post-type for EventChamp 'event' and woocommerce 'product'?

I'm trying to combine the search for event and product. But i unable to get the result by price. $arg = array( 'post_status' => 'publish', 'ignore_sticky_posts' => true,...
0
votes
1answer
35 views

Get every post with value in meta key

I am trying to get every post, that has a specific URL in the meta key _cornerstone_data. From the WordPress documentary I was able to build this query, that probably gets me close to what I'm trying ...
0
votes
0answers
27 views

wp_meta_query checking for array items in array?

I am struggling with a search-box to filter some custom fields. One of the meta-fields contain an array of one or more choices. How to set up wp_meta_query so that it returns the post where any of the ...
0
votes
1answer
25 views

Meta query not showing result properly

In wordpress posts I have custom meta fields (ship from, margin price). I want to filter post by these meta fields. Ship from fields contains multiple value (Example: A product can be ship from china ...
0
votes
0answers
14 views

make pagination on single-gallery with content from meta value

I have a file single-gallery and this content is image from meta_value , and i want make pagination for limit show image per page on all post , this my code $paged = (get_query_var('page')) ? ...
0
votes
0answers
15 views

Sorting meta_query of custom post type

I have 2 custom post types Transit and Colors, connected with a relationship - as a transit post has a custom field to select a color post that it will belong, that stores the Color post ID. I ...
0
votes
2answers
36 views

Setting proper query for multiple custom admin filters

I am adding custom admin filters for my custom post types. I am a bit confused about how to go with the parse_query filter in order to have my posts filtered based on 2 or more filters. Initially for ...
0
votes
1answer
144 views

Meta Query Array Error 500

I have two CPTs – Match and Player. Each Match post entry contains details relating to a specific match (who played, scorers, etc.). This info is inputted via ACF Post Object fields corresponding with ...
1
vote
0answers
29 views

How to show recent and upcoming birthdays using meta_query

I have a date of birth user field, I am trying to show recent (past 7 days) and upcoming (next 7 days) birthdays. I have the below but it is not working because the years in the date of births are ...
2
votes
1answer
62 views

Use meta_query to display events by date in custom field

I'm working on a template for a specific category archive of the custom post type event. I need to make a query that shows future and ongoing events, ordering by a date in custom field. $termName = ...
2
votes
1answer
137 views

Display custom post types with custom date field value (before today) & order by custom date field

I'm trying to display custom post types with custom date field value being before today. It works OK for showing posts before today, but the order is only based on post date. I want to have the result ...
0
votes
0answers
157 views

Search for custom post type with acf fields

I am following the idea of Mayeenul Islam for creating a search for custom post types available here This link. However ,I want to use ACF repeater sub fields in the query.So,I have added another ...
1
vote
2answers
29 views

Is it possible to set specific posts to show first in a query?

Please forgive me if my question isn't the clearest and I'm not using this exactly correct... I've never posted before. I am trying to setup a query on a real estate website that I'm developing that ...
2
votes
1answer
137 views

Working Bootstrap Carousel Conversion to WP - Technical Questions

I have coded a working Bootstrap carousel, it needs to be converted to WP. It's a small chunk of the site, but as a Wordpress newbie, am stuck in understanding the technical issue. So here's what I ...
1
vote
1answer
47 views

How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?

I'm trying to include post meta in the scope of a WordPress search using WP_Query. I have a meta query that looks like this: $args['meta_query'] = [ 'relation' => 'AND', [ 'key' =...
2
votes
1answer
62 views

Advanced WP Query hogs the SQL server

I recently developed a website for a customer who is a estate agent. Included in the project is a post type called listing. This post type is used for all of their listings and additional information ...
0
votes
1answer
44 views

Custom Query: If One Post Object Field Value Is The Same As Another

Is it possible to construct If/Else queries that look to see if two (or more) Post Object fields are the same – i.e. echo X if Post Object field 1 'value' is the same as Post Object field 2, else echo ...
0
votes
0answers
24 views

meta_query compare > not working

I have a WP_Query function that uses these arguments: $args = array( 'post_type' => 'exhibit', 'post_status' => 'publish', 'meta_query' => array( ...
0
votes
1answer
28 views

How to hide posts of a specific custom category in Wordpress?

I have 2 custom post types on Wordpress website - Location and Event. Location is connected with Event as meta data (for sorting). For example: some event (Event post type) is taking place in London (...
0
votes
0answers
18 views

How to compare date and string inside a serialized array fro REST API v2? [duplicate]

I have saved a meta data for a single post called "event" as an array like below (serialized for sure) and I would like to filter for "place" and also "date" which will be after or before some sort of ...
5
votes
2answers
108 views

WP_Query orderby custom field then post_date in one query

I need to order the first three posts by a custom field, and subsequent posts by post_date in one query - for example: Post 4 (field_order: 1) Post 3 (field_order: 2) Post 2 (field_order: 3) Post 1 (...