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
1answer
2k views

wordpress get meta value by meta key

How to get the meta value by meta key I want to get the value by the meta key. This is what I have tried so far: $args = array( 'post_type' => 'post', 'post_status' => 'publish', ...
2
votes
1answer
302 views

Using database meta_values to calculate new post order using pre_get_posts or a 'request' hook

UPDATE: I have worked out my implementation of the selected answer at the bottom of this post. I'm implementing a sorting algorithm based on Reddit's hotness algorithm, in addition to a time-decay ...
0
votes
1answer
37 views

Filtering problem

I got the custom_post_type_data in which I store some variables when I make a new post. Variables likes Author, Price etc. I implemented a filtering by author, so when you click on James (for ...
0
votes
1answer
155 views

meta_query fails to compare on values containing apostrophes

I have WP Query and I am simply comparing by the meta value by = My value contains town names, and seems to work great for the majority of names. However some names contain apostrophes... Madonna ...
1
vote
1answer
317 views

How to add a new meta key and assign timestamp to posts

I've been trying to look for a way to create a loop in my website and show posts being read/watched but have not found anything. The only way I can accomplish this would be to create a new meta key ...
2
votes
1answer
260 views

order by meta_value serialized array

Hi I'm trying to pull posts using the wp query. Just one problem--I am trying to sort the posts alphabetically by a certain meta_value. Thing is that this meta_value is a serialized array. Is there an ...
0
votes
2answers
690 views

How to: get_user_meta - BuddyPress

What is the proper way to display User Meta in the BP Loop using this line from codex? <?php get_user_meta($user_id, $key, $single); ?> I added that line to the profile loop and switched ...
2
votes
2answers
1k views

Sort Posts by Multiple Meta Values

1) Custom Post Type named "Buying_Locations" 2) Each Post has three meta values of: State, City, Store Name QUESTION: How can you show a list of these posts sorted alphabetically by State, then ...
0
votes
3answers
2k views

LIKE %…% Meta Query

I have a serialized array as a meta value and I'm trying to run WP Query where it finds a specific value in the serialized array. Here's an example of the serialized array field: ...
0
votes
1answer
276 views

Meta query - How to display a null meta key

At the base I have this query wich displays 9 randoms custom post type : $args= array( 'post_type' => 'adverts', 'orderby' => 'rand', 'posts_per_page' => 9, 'tax_query' => ...
1
vote
1answer
485 views

Using OR in WP_Query negates the “NOT EXISTS” compare

I'm attempting to filter posts by a custom field that either are equal to 'new' or have not been set yet. I'm able to get either of those meta_queries to work on their own but when I use them in an ...
0
votes
1answer
324 views

WP_Query arguments: Loop through custom post type - get all entries except excluded meta_key?

Can't seem to find out what I'm doing wrong. $args = array( 'post_type' => 'wr_event', // my custom post type 'posts_per_page' => -1, // show all posts 'meta_query' => array( ...
1
vote
2answers
500 views

Multiple Values stored as array in Meta Query

I'm a little confused as to best practise for saving multi-select values in meta fields. Assuming <select multiple name="_casestudypost[]"> is my form field if I store ...
0
votes
1answer
378 views

datetime picker, timestamps and meta queries

I have a custom meta box with a datepicker. The datepicker outputs 2013-01-17 10:00 in my database for an event that is 01-17-2013 at 10pm PST. $eventlist = new WP_Query(array( 'post_type' => ...
2
votes
0answers
102 views

Is it possible to orderby multiple meta_keys when using meta_value_num?

Reading through the order & orderby documentation, it's not clear to me whether there is any support to order based on multiple meta_key values. Obviously, using meta_query I can return posts ...
0
votes
1answer
1k views

get_users meta_query

I can't get meta_queries working correctly on get_users(). For the life of me can't figure out what I'm doing wrong. $args = array( 'meta_query' => array( ...
2
votes
1answer
522 views

How to exlude posts that have certain meta_value?

I want to exclude some posts from the home page. So I want to use meta data, and filter all posts that are signed by meta_value=0. Like this: $args = array( 'posts_per_page'=>28, 'meta_query' ...
0
votes
1answer
712 views

How to query posts with featured images

I basically want to use WP_Query to select 3 latest posts which have featured images and this is the only way I can think of. regards edit tried $query = new WP_Query( array( "post_type" => ...
3
votes
3answers
2k views

Using meta query ('meta_query') with a search query ('s')

Trying to build a search that not only searches the defaults (title, content etc) but also a specific custom field. My current query: $args = array( 'post_type' => 'post', 's' => $query, ...
2
votes
1answer
775 views

Order by meta_key with two meta_queries

This should be simple, but I just can't pinned down a good example of the correct syntax to do this. I want to order by the specified meta_key with two meta_queries. The problem is query_posts ...
0
votes
1answer
173 views

loop through custom post-type with two meta_keys

I have a custom-post-type named my_project. This post-type has two meta-boxes: is_featured is_featured_position So essentially in my backend of the post-type I can set a checkbox for is_featured ...
0
votes
1answer
426 views

Custom query (author is post_author or meta co_author) with Pagenavi pagination

I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi. The query is something like this (omitting $wpdb ...
3
votes
1answer
3k views

Nested meta_query with multiple relation keys

I am curious whether Wordpress is able to run nested meta_query, with each having different relation keys? As of Wordpress 3.0, tax_query is able to perform this function; I'm wondering whether this ...
0
votes
1answer
334 views

WP_Query meta compare must include ALL array values

I am allowing users to query posts using a form with checkboxes. I want the posts to be filtered by the checkboxes but instead of showing all posts that include the ANY of the meta values selected I ...
2
votes
3answers
174 views

meta_query results not the same with and without spaces

I have a meta_query that gets all the items with a price range between 2 variables. My problem is that 10 000 is not the same as 10000. How can I fix this? I have been googling but I'n not sure what ...
0
votes
2answers
917 views

pre_get_posts and set

I have some functions into my pre_get_posts filter. So, the problem is that when I set a meta_query, all the menus disappear from the page. function propersearchfilter($query) { $taxarray = ...
1
vote
1answer
381 views

How can I combine meta_query queries?

I'm trying to build combined meta_query queries but they don't work. Any ideas how I can implement queries like the example below? Thanks, Hinnerk Array ( [relation] => AND [0] => ...
0
votes
2answers
86 views

list or get meta_key where meta_value is 'something'

I'm trying to get with get_user_meta the meta_key where the meta_value is 'ive-read-this' But I do not get the value. What should I do?
1
vote
1answer
171 views

query order by date on custom type: wrong order

I know there are very similar questions ans answers out there already, but I simply cannot get my query to get into the right order. I have a custom post type ("bb_articles") with custom fields, ...
0
votes
2answers
2k views

Wp_query order by multiple custom fields?

I am learning WP_query and recently ran into a problem. I need to do a query where i first filter trough one or more custom fields, which works great thanks to meta_query. However, i also need it to ...
10
votes
2answers
9k views

Meta_query compare operator explanation

I noticed that there are bunch of operator can be use for compare in meta_query. However, I am not quite sure what operator I should use, it is somehow confusing like = and LIKE operator. I would ...
0
votes
2answers
157 views

Query author's posts & posts that have author's id as meta value

I am trying to get posts with an author's ID as a meta value in the author.php template using additional request parameter. For example I want posts with john's ID as a meta value using a request ...
1
vote
1answer
138 views

How to stop wp_postmeta from being called on archive and search pages?

Currently, when I load a search or result page, it queries the wp_postmeta table which is leading to the page taking ages to load. I realise this is a result of this table being huge (70k rows), and ...
2
votes
2answers
249 views

What is an efficient way to query based on post_meta?

The problem I am having is when I allow users to filter posts it overpowers the database and things run extremely slow. I am unsure what the best way to query posts using meta values is. My site has a ...
0
votes
1answer
170 views

WP_Query Class custom field parameters

In the the class WP_Query, using the meta_query(array). The wordpress codex says that the 'value' is a string|array. The array support is limited to a compare value of 'IN', 'NOT IN', 'BETWEEN', or ...
1
vote
1answer
111 views

Get content from pages with same meta_key from Database

I need help! I'm doing this template page and I want to get content from pages with the same meta_key. I want to display all pages thumbnails that has the value "red" in the meta_key. The problem is ...
5
votes
3answers
1k views

Complex meta query with 3 keys

I think the problem essentially relates to sql query structure and I am not an expert.... I need to search for posts (custom post type) by 2 parameters: pd_city pd_country Please note that ...
1
vote
1answer
126 views

Filter posts by meta query?

I made custom post type and used a meta query … For this link: ...
7
votes
2answers
411 views

meta_query sorting by 2 keys

I need to sort (custom) posts by 2 custom field values... custom field name 1: is_sponsored [ value can either be 1 or 0 ] custom field name 2: sfp_date [ timestamp aka current post date in seconds ...
0
votes
3answers
345 views

get Insert id for meta field

I'm in a situation where i also need to get the id of the inserted meta( meta_id for post meta and umeta_id for user meta) For eg i add a user meta ...
1
vote
1answer
233 views

meta_value_num sort glitch

i have a custom query, and I have a meta key that contains a sequence number: 1.1, 1.2, 2.1, 2.2... 11.1, etc the problem occurs when the numerical sequence gets in to double digits, ie. 5.11, 5.12, ...
2
votes
1answer
3k views

Can I query custom meta data through WP_Query

Ok, my question is a bit complex so I will try and give a general explanation and then go into details afterward. I am running WordPress 3.4.2 and I am using WCK Post Type Creator and WCK Custom ...
1
vote
0answers
293 views

How to filter a query by multiple meta keys and order by other meta keys

I'm trying to query posts using WP_Query and meta_query parameters: $args = array( 'post_type' => 'produkty', 'meta_query' => array( 'relation' => 'AND', array( ...
0
votes
1answer
1k views

meta_query with array as value

I am writing some PHP which allows users of my site to submit a form and query posts by their post_meta. Everything works fine except for one thing, I used Advanced Custom Fields to create the ...
0
votes
1answer
370 views

Meta query: get posts with value in a multidimensional array

I have a custom post type, Album, which has a custom field called 'tracklist'. Tracklist is a multidimensional array which contains a track title and track link, like so: $tracklist = array( [0] ...
-2
votes
1answer
139 views

Get all user with both meta_value

I was wondering if there were any efficient way of fetching all user comparing two different meta_key. I am currently fetching all user compared to the first meta, then loop trough the user_id to ...
1
vote
1answer
302 views

Filter posts with meta_query NOT IN where value has multiple values

I would like to use a meta_key to store multiple values in that key. Thereafter, I would like to filter away posts that do not contain a specific value in the key. In other words, just show posts ...
1
vote
1answer
839 views

search query within custom taxonomy term, post title and meta field

I want to create a search that does: Search within my custom taxonomy - custom-tags search the post title search select meta field ?? dont know search with custom post type - easy part I looked ...
0
votes
1answer
154 views

Querying meta values within an array

Okay so I'm using the relationship field from Advanced Custom Fields against a custom post type. The relationship lists countries, when these are saved they are within a serialised array: [country] ...
1
vote
1answer
366 views

Use meta_query to get title of associated post

I have two post types that I've associated in one direction by assigning Post A as a custom meta field of Post B. I need to search based on the titles of Post A and return the associated Post B ...