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
19 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
18 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
29 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
15 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
27 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
38 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
20 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" ...
0
votes
1answer
44 views

How to query for custom field within Gutenberg block from outside of that post?

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
16 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
20 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
17 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
14 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
96 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
29 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
32 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
18 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
11 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
45 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
31 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' => '...
0
votes
0answers
46 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
38 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
22 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
37 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
28 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
5 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
38 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
18 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
45 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
2answers
15 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
50 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
17 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
22 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
24 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
18 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
1answer
40 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
43 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
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
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
69 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
41 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
54 views

Meta_Query with multi select values

I have the following: $int_args = array( 'post_type' => 'intervention', 'meta_query' => array( array( 'key' => '...
0
votes
1answer
36 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
1answer
34 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
17 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
81 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
154 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
44 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 ...