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.

learn more… | top users | synonyms

1
vote
0answers
24 views

Help ordering Post loop by two meta values

Background: I have a custom post type "events" which has a post meta value of a unix timestamp called event start date. I also have a post meta value of ticket_status that has 3 possible values (S=...
0
votes
1answer
19 views

Create a WP_Query where if the first value of the first row is equal to the second compare other value

I want to create a query of a custom post type where the order is by a custom field and I want if the custom fields are equal to compare a second custom field. $args = array ( 'post_type' => ...
0
votes
1answer
20 views

meta_key and meta_value not working together

I am trying to filter the loop to find posts that have a meta_key with a specific meta_value. I've looked at the Codex, and I've tried the following with no luck: // No results $args = array( '...
0
votes
1answer
15 views

How to make Meta Query case sensitive?

I have a meta query similar to: $posts = new WP_Query( 'post_type=article&meta_key=kln_aid&meta_value=' . $aid ); where I need aid to be case-sensitive. Is that possible via Meta Query?
1
vote
1answer
23 views

Performance when getting post meta for post retrieved by meta value

I have a meta key which I would like to use to get all post meta data for a post where that one meta key matches a specific value, in one go. Example: Post 1 has a meta_key called unique_number. I ...
0
votes
0answers
20 views

Very slow query for getting posts with postmeta

I have an heavy query generated by an search page which should get filtered posts based on some meta data. SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( ...
2
votes
1answer
21 views

How to update single value in multi dimensional Post Meta?

There are some values in Post Meta Data stored as a multi dimensional array. I want to update some of their data. Here is the Post Meta value displayed using <?php the_meta(); ?> voter: a:1:{s:...
0
votes
2answers
36 views

Wildcard with LIKE operator in Meta query

I have a form on a page that search property with a location field and I used the following meta query to process the search; $location = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']); ...
-3
votes
0answers
24 views

Customize Woocommerce Product Widget to show only free products

What I want to do is to show only products which _sale_price is equal to zero. I have a created a new 'case' in WC file responsible for class-wc-widget-products.php like that: case 'free' : ...
-1
votes
0answers
19 views

Custom Query With Meta Value [on hold]

I want to get my posts from the "cafe" post type with this filter, but it doesn't work. This is my custom query: $args = array( 'post_type' => 'cafe', 'meta_query' => array( ...
0
votes
0answers
14 views

Fallback meta_key if first has no value?

I'm using the code below to get all items from a particular category that have a date field with a value either equal to today or in the past. The problem is that there are two different date fields – ...
0
votes
1answer
89 views

Using get_terms() with meta_query parameters

Im trying to build a taxonomy query to only display the terms that have a certain custom field value assigned to it. The custom field holds a boolean value, so I tried: $args = array( '...
2
votes
1answer
33 views

How metadata API works?

Update 2: Check out @NateWr method using add_post_meta with the default post: add_post_meta( 1, 'my_items', 1 ); add_post_meta( 1, 'my_items', 2 ); add_post_meta( 1, 'my_items', new \stdClass ); ...
-2
votes
1answer
48 views

Get Posts ordered by a date custom meta field

I have created a meta field for a custom post type. This is a date field that will always be YYYY-MM-DD. There could be 100s of posts so i cant query them all and sort afterwards. I need to be able to ...
3
votes
1answer
38 views

Sorting posts by multiple values, combined

In this image, 1. The Black letters are default post titles 2. The number before the 'of' is a custom field. 3. The number after the year is the post's published year Now I want to sort this ...
0
votes
0answers
49 views

Order ascending is ignored in meta query?

I'm using pre_get_posts to alter my main query and attach a meta query to it. This is on a woocommerce products archive page (...not sure if that would make a difference). function has_upcoming_date(...
0
votes
0answers
24 views

WP Meta Query at depth 2

I'm interested in doing a meta query according to some post data that doesn't exist at the first level of the post meta. In other words, I would need two or more keys to get to the variable I'm ...
0
votes
1answer
28 views

wordpress meta value compare between two date

I want to check date between two year of birth. But my saved value is date of birth. Meta key "birth_date". Now I want to check value between years using year. My saved date format like "01/01/1995" ...
0
votes
0answers
16 views

How to add OR condition in wordpress main seach box Query?

I'm trying to search from main search text box. Custom post type "course" and it custom taxonomy 'Location'. It I search with "USA", In data it looks for 's'= 'USA' AND 'loaction'='USA'. What I ...
0
votes
1answer
27 views

Query events post type after current date and timezone

So I am making changes to a clients website and currently they have an events post type with some custom fields that allow them to set an events end date/time and the events timezone. The custom ...
0
votes
1answer
31 views

Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]

I'm currently facing a little problem. I'm using ACF plugin which generate complex meta_key names when creating hierarchical fields. I found in my database meta_key named modules_1_content_0_module. ...
1
vote
0answers
16 views

Alter main archive, to show posts with meta as last

I'm having troubles with getting posts with meta_value "sold" as last in the main query of my custom Post type. The best/easiest way i can think of at the moment is to filter the "sold" posts out of ...
0
votes
1answer
30 views

get_users meta_query: REGEXP not working for matching new lines

I have a meta field "my_meta_field" which may contain the following for these sample users: User A 99999 559225 12519 User B 5020492 99999 125191 User C 194295 1199999 Newlines are \r\n or \...
3
votes
1answer
93 views

Using WP Query to search within ALL keys in meta query

What is the best way to create a meta query that searches through ALL meta fields (keys)? What I'm trying to do is something such as: $posts = new WP_Query(array( 'meta_query' => array( ...
1
vote
1answer
36 views

Custom query, checking values of multiple meta keys

I am using two plugins, and I have some issues combining them. One is an event calendar, which add new meta keys to posts, the other is a show-posts-as-grid plugin, that fetches the event posts from ...
1
vote
1answer
29 views

Archive post by meta value + 24hours

I'm using this code to archive some custom post type : $where .= " AND wp_postmeta.meta_value >= now()"; The metavalue is a date field. On the day of the value of the datefrom has been setup the ...
1
vote
1answer
31 views

Adding an array from a query string to a WP meta_query

I am collecting values from a query string as an array. Then collecting those values and placing them into the value of the 'meta_query'. I am having trouble where nothing gets outputted from the ...
0
votes
1answer
24 views

Can I use pre_get_posts to add up values from two different meta_keys?

I'm storing post meta values _likes and _dislikes in postmeta. In some cases, I want to be able to query for posts by their netto score (likes minus dislikes) and order them by it. I'm familiar with ...
1
vote
1answer
37 views

Using meta_query and custom fields within pre_get_posts to return posts within a numerical range

I'm trying to build a search page for music tracks that lets visitors: Choose the post type Choose a genre Choose a mood Specify a Beats Per Minute (bpm) range wp_dropdown_categories() is working ...
0
votes
0answers
31 views

Best way to Order Post in Home without a plugin

We are trying to reorder one section of the home page. our approach was with meta_keys and meta_values WP_Query Sample: <ul id="featuredMain" class="feautrued-main"> <!-- Main ...
2
votes
1answer
56 views

Advanced orderby with multiple meta_query

I am on latest version of WordPress. I have scoured the codex concerning wp_query and meta_query. I also read through these: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-...
1
vote
1answer
40 views

Get posts with multiple meta values

I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array(...
0
votes
1answer
21 views

How to sort posts according to meta value?

How can I sort all the posts according to their meta value? I am using the below code: $args = array( 'meta_query' => array( array( 'key' => 'wpcf-stream', '...
0
votes
1answer
87 views

How to provide meta_key array to wp_query?

I'm trying to build a wp_query, so far I've managed to get desired result using following query. $args = array( 'meta_query' => array( 'relation' => 'OR', array( //check if ...
0
votes
1answer
29 views

WP_Query returns empty if meta_query has more than 7 values

I have a custom loop to display a custom post type 'properties' . The idea is to search properties based on different search parameters selected by users. Now the weird problem I am facing is that if ...
1
vote
2answers
91 views

meta_query key value from array

I have a custom post type called 'game' with some ACF fields. One of the fields is a Post Object(called review_link) that accepts posts from a category called 'reviews'. One other field is a taxonomy ...
10
votes
3answers
319 views

Filtering multiple custom fields with WP REST API 2

I want to filter posts based on multiple acf custom fields with AND relation. Something like this: $args = array( 'post_type' => 'product', 'meta_query' => array( '...
-1
votes
1answer
21 views

Filter Query Post by Custom Fields(by date)

I want to filter query_post using the 2 meta keys start_date and end_date, i want to get my posts to divide it by upcoming events and past events. start_date and end_date is stored in the timestamp ...
0
votes
1answer
25 views

Attachment Metadata inside of Loop

Basically, I'm trying to call attachment info to display withing a loop, for use in an image gallery. I know I need to use wp_prepare_attachment_for_js($attachment_id) but I can't seem to get anything ...
0
votes
1answer
157 views

WP REST API - get custom taxonomies based on terms & filter

I need to get the list of data's with taxonomy term property_category,based on this property_category having data's like apartment,house,office etc.For example localhost url given http://192.168.0....
0
votes
0answers
31 views

Orderby one meta key, remove posts with another

I am trying to order custom posts with a custom taxonomy with a meta key value. I am also trying to remove posts from that loop if they are past the date set by another meta key. Here's my code: ...
0
votes
3answers
71 views

Can't figure out query logic

Help me figure out how to structure this meta_query within my post query! There are two taxonomies attached to my post type ('audition_type', and 'union_requirement'). On a page of my site the user ...
0
votes
0answers
33 views

Is it possible to search for a string in posts OR postmeta?

If I have a text string $search_string and construct a query like this: $args = array( 's' => $searchstring; 'meta_query' = array( array( 'key' => 'my_key', 'value' =&...
0
votes
0answers
18 views

meta_query in $args ignored when called from theme

I have the below function in my plugin in the MyManager class. public static function test() { $numRowLimit = 6; $arrArgs = array( 'posts_per_page' => $numRowLimit, '...
0
votes
1answer
39 views

WP Meta Query - mixed AND / OR query doesn't work

I am absolutely boggled by this one. I am creating a search function for a property site - simple enough. Simple queries such as max_price, max_beds, rent_or_buy work ok. But I am trying to create a ...
0
votes
1answer
35 views

meta_query 'compare' => '!=' not working

I am using a custom post-type, in post there are a checkbox meta field for featured post. So there are two scenarios. First with featured posts Second with non featured When I called featured ...
0
votes
1answer
28 views

Unpublish Authors With not Fulfilled Fields

I want to unpublish profiles of users that doesn't have all extra fields that I've created filled. I use a custom meta_query in a user taxonomy in order to filter those authors, and that work, but it ...
0
votes
1answer
47 views

Exclude posts with certain meta data from search results

I'm trying to exclude al posts with certain meta data from the search results but so far it's not working. Here's the code I'm using: function ZoekGeenLegeItems( $query ) { if( is_admin() || !$...
0
votes
1answer
28 views

query post by author gender

I'm using utimate member plugin on my website. for each member (author), I have a field to store the member gender. (Homme / Femme). the data is stored in my database, inside wp_usermeta. meta key ...
0
votes
1answer
50 views

Wp_query with 2 meta keys and array of meta values

Hi in my post_type=shop i have 2 meta keys and array of values Custom fields Name Values cu_status pending,processing,completed cu_date 12-Jan-2016 , 13-Jan-2016, ...... any ...