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

11
votes
6answers
8k views

meta_query with meta values as serialize arrays

I'm working on a project in which I'm creating a custom post type and custom data entered via meta boxes associated with my custom post type. For whatever reason I decided to code the meta boxes in ...
10
votes
2answers
10k 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 ...
8
votes
1answer
226 views

Mixing regular and custom post types (with meta_query) on home page

Not sure how to achieve this. I'm trying to mix standard posts and custom posts on a site homepage but I only want to display the custom posts if a meta value is set. Displaying the posts works fine ...
7
votes
2answers
413 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 ...
6
votes
1answer
9k views

How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?

I've been troubleshooting an issue over the past few days and keep going in circles. Could really use a fresh pair of eyes to help me answer this question... So I'm working with a wordpress site ...
5
votes
1answer
4k views

Using meta_query, how can i filter by a custom field and order by another one?

With the following code (in functions.php) my posts (of CPT event) are ordered by _end_date instead of _start_date. What's the proper solution to this as of WP 3.1.3? Of course I'd like to avoid using ...
5
votes
1answer
725 views

how to show posts that are missing a meta_value

How can I build a query to find posts that DO NOT contain a certain meta key or meta value? for example: query_posts( array( 'meta_query' => array( array( 'key' => 'feature', ...
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 ...
5
votes
3answers
510 views

Using meta_query on pre_get_posts to exclude a particular meta_key value

I have a simple filter running on the main query on the front page, it should be excluding all posts with a particular meta value (by only including posts who do not have the meta_key set, or those ...
4
votes
4answers
4k views

Fail to compare dates in meta_query

This is the piece of code I use to get event posts whom date metadata is newer than today : <?php query_posts( array( 'post_type' => 'concerts', 'meta_key' => ...
4
votes
4answers
3k views

meta_query for keys that aren't yet set

I'm trying to query for a custom post type for a gallery system. I have a checkbox to set a gallery as a "featured" gallery (set up through More Fields plugin) - if this is checked then the meta value ...
4
votes
1answer
1k views

Changing the meta_query of the main query based on custom query_vars and using pre_get_posts

I've registered custom rewrite rules and query_vars to use for displaying a list of events based on ISO date format. For example when a user requests the URL, http://site.com/by-date/2013-04-04/, my ...
3
votes
3answers
2k views

SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='price'… stops working when value is over 999

Overview: I am not trying to return a post. I simply want the single highest value for a particular meta_value across all posts... just the value itself. Details: I have added a custom meta_key ...
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 ...
3
votes
2answers
951 views

Query between two meta keys

I feel like I'm extremely close on this one but the query keeps on showing up empty. Basically, I'm trying to query the custom values between two dates. Records should be returned if the start date is ...
3
votes
2answers
193 views

How do you get posts by meta_query using the JSON API plugin?

I would like to get post with an API method using a kind of meta query. I have 2 custom fields "place" and "dayoweek" and I want to retrieve via API call all the post that have some values for this 2 ...
3
votes
2answers
272 views

Best practice - Meta Query vs. post_clauses for “left join” ordering

Moreso a psuedo-code question than actual code. I have some custom post meta attached to attachments, and created a list table column for this meta. The meta is either 1, or null (not set), but I am ...
3
votes
1answer
3k views

Meta Query with AND & OR?

I'm trying to do some filtering for some posts in WP_Query, but I can't seem to get the right condition. Basically what I wanna do, is get posts that have the custom field event_data (sorted by this ...
3
votes
1answer
2k views

WP_Query with checkbox meta_query

I have posted this on StackOverflow too, not sure if that's allowed - if not let me know and I'll remove one (I don't want to look like I'm spamming). Anyway.... I have a custom post type and have ...
3
votes
2answers
193 views

Search multiple meta keys at once

How would I modify the following SQL Query to allow me to search multiple meta keys at once? e.g. user_business AND user_about In the end I'll be searching about 40 - 50 different meta keys; or if ...
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, ...
3
votes
1answer
217 views

Is there a way to do multiple ordering on a multiple meta_query?

I'm experimenting with searches and multiple criterias and ordering. Let's say we have a real estate site, all posts have 2 custom fields (price and surface), and we want the visitor to be able to ...
3
votes
1answer
2k views

Querying custom post type with 2 custom fields (date-range)

I've searched WP Codex and StackExchange and gotten some clues, but I can't get this query working. I have 2 custom fields associated with each exhibition in Y-m-d format: exstart-date being the start ...
2
votes
1answer
587 views

WP_Query() show posts that end later than today

I have a query as follows: $wp_query = new WP_Query( 'meta_key' => 'end_date', 'meta_value' => 'today', 'meta_compare' => '>=', 'post_type' => 'vehicle' ); ...
2
votes
1answer
1k views

Using custom meta_query with relation not working as expected

I am trying to create a query to pull future events only. It was working great until the client requested the ability to add date ranges--so the event will either have a start date only, OR a start ...
2
votes
1answer
120 views

Exporting Data from WordPress into a flat table

I need to be able to export the data within WordPress so that each object is contained in a single row, like a flat table. Imagine each post type as it's own database table, containing columns that ...
2
votes
1answer
475 views

Perform query with meta_value date

I am trying to perform a query on a custom-type post using the value of a custom field. This field contains a string date: dd.mm.yyyy. The post type name is 'event' The custom field name is ...
2
votes
2answers
1k views

Archives for custom post type based on a “date” meta value

I've got an "Event" custom post type. Each post has a meta field for the actual event date, which cannot be the posts's publish date, as most all the event dates will be in the future. With that, I'm ...
2
votes
1answer
237 views

Order Posts by Taxonomy and Meta Value

It's possible to order posts by Meta Value. It's possible to order posts by more than one value. And thanks to the code below it's possible to order by taxonomy. But how can I alter the code below ...
2
votes
1answer
528 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' ...
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 ...
2
votes
1answer
582 views

How can I query all users who registered today?

I'm trying to use meta_query to return all users that have registered today : $args = array( 'meta_query' => array( array( 'key' => 'user_registered', ...
2
votes
2answers
925 views

Custom query variable - get wordpress to redirect to nice permalink url

I have been looking for an answer for the last couple of hours but could not find anything pointing me in the right direction. Some advice would be very much appreciated! What I already have: A ...
2
votes
2answers
728 views

Sorting: custom query with orderby meta_value_num THEN by title

i try to run a custom post type query to match following criteria: sort movies first by year in descending order, after that ("inside" the year order) by title alphabetically. desired output: ...
2
votes
1answer
303 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 ...
2
votes
1answer
783 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 ...
2
votes
3answers
176 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 ...
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 ...
2
votes
2answers
259 views

Trying to perform complex custom field query with order by set to field value

I've got two custom fields for event posts: event-start and event-end. When I'm querying for current events, I'd like to show any post where the event-start OR the event-end is greater than or equal ...
2
votes
1answer
491 views

WP_Query display next custom post from today's date

I have a calendar plugin that uses custom posts types to create events. There are several custom fields that allow me to create various and seemingly unlimited post queries. The one I'm currently ...
2
votes
1answer
30 views

wordpress custom_meta ordering of timestamps

So I have a wp meta query that is handling the searching of events which have a start timestamp, and an end timestamp, I want to return all results within the two dates a user picks in the search. ...
2
votes
1answer
67 views

XOR functionality for meta_query

I'm trying to resolve the problem with event displaying. An event has its start and end dates, written in meta. For example, event starts on (dmY) 03.04.2013 and ends up on 08.04.2013. Using WP_query ...
2
votes
1answer
261 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 ...
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 ...
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 ...
2
votes
1answer
398 views

Meta_query with relation 'OR' killing server CPU

function get_nb_offres( $typeOffre ) { global $type_bien_correspondances; $args = array( 'post_type' => 'annonces', 'meta_query' => array( 'relation' => ...
2
votes
2answers
121 views

CPT Meta Searching

I'm developing a WP plugin which uses custom post types and meta data. What I'm trying to achieve is having the meta data searchable. Here is some code that I found which searches the meta data fine, ...
1
vote
2answers
798 views

WP_Query not working as expected for attachments and custom meta_query

If I use get_posts() like so I get a number of results with the value 1 for the my_key meta_key: $posts = get_posts( array( 'post_type' => 'attachment', 'meta_key' => ...
1
vote
2answers
503 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 ...
1
vote
2answers
281 views

How do I find if a page has a template?

So I'm doing a query like this: $the_query = new WP_Query( array( 'meta_key' => 'homepage', 'meta_value' => 'yes', 'post_type' => 'page', 'orderby' => 'modified', 'posts_per_page' ...