Tagged Questions

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
497 views

WP_Query using meta_query with relation OR and orderby meta_value doesn't work

I've been bashing against a bug for a few hours now, and can't seem to find my error. Could there be a bug with the relation type 'OR' in WordPress? $evenements = new WP_Query(array( 'post_type' ...
0
votes
3answers
1k views

Custom Query With Multiple Meta Key Value

I am new with WordPress development and I have found this query and I want pass multiple key and value in this query. My Query is: $querydetails = " SELECT wposts.* FROM $wpdb->posts ...
0
votes
1answer
25 views

Filter meta request

i've got a multisite where i query specific custom post types from one specific blog. It looks like this: function unify_results_filter( $input ) { global $wpdb; $blog_id = get_current_blog_id(); ...
0
votes
0answers
121 views

meta_query compare not working

I'm trying to run this WP_Query on tag.php, and it doesn't seem to work. $tag = get_query_var('tag'); $args = array ( 'tag' => $tag, ...
0
votes
2answers
67 views

I would like to have add_post_meta to return the ID instead of true or false

I would like to know if there's a way to have the ID when we use the add_post_meta() function ? I need it so I could remove it using ajax calls. Is there a way to retrieve it or I'll have to make a ...
0
votes
2answers
64 views

Is it possible to load a different sidebar in single.php based on a meta_query filter?

I have a custom post type 'speakers' and I have a checkbox custom field (meta_query) to separate my Conference speakers from my Workshop speakers. I can filter my speakers with this meta_query and ...
0
votes
0answers
65 views

Sort posts in dashboard using custom field; also include posts where field isn't set

I'm using a pre_get_posts filter found on this question thread here, to sort a custom post type in the dashboard: function xyz_event_sort_order( $wp_query ) { if ( is_admin() ) { ...
0
votes
0answers
79 views

Orderby custom date fields with meta_query broken on OR relation

I have an 'event' post type that has custom start and end date fields. In a block on the home page, I'm trying to show only upcoming or ongoing events. So, to achieve this, I'm doing a meta_query that ...
0
votes
1answer
74 views

Passing conditional arrays to WP_Query() [closed]

I've looked around at a few places and could not find an answer. I was wondering what the best way to create a WP_query from possibly empty variables were. I have about 16 of these $_GET variables. ...
0
votes
0answers
21 views

meta_query works with single query but not multiple queries

This is very strange and I'm not sure why it is happening but this piece of code... $args = array( 'post_type' => 'property', 'sentance' => true, 'meta_query' => ...
0
votes
1answer
40 views

query post based on comparison

Each post in my site can be rated as 'good' , 'ok' , 'bad'. The values are stored in custom fields. I now need to show top 10 posts with maximum 'good' and it should not display posts with greater ...
0
votes
0answers
84 views

Multiple metadata checkbox sorting

I'm searching for a while but cannot figure how to do exactly... I want sorting my custom post type posts with multiple checkboxes metadata in front-end of an archive page. All store in a session. ...
0
votes
0answers
32 views

Wordpress Query Default Order if Meta Values Same?

If the main query args look like this: 'orderby' => 'meta_value_num', 'meta_key' => 'price', 'order' => 'DESC' What orderby does the query use if the meta_key value is the same for ...
1
vote
0answers
174 views

WP_Query with meta_query dosen't return results

I am trying to get list of posts filtered by fields I added using the advance custom fields plugin. I have more fields that I want to use but it doesn't work as I want it to. Here is what the query ...
0
votes
1answer
572 views

Matching Serialized Arrays with meta_query

I've asked a related question previously, but I think I've finally worked out the crux of my issue. I'm using Advanced Custom Fields and have a number of custom fields attached to my post type. I'm ...
0
votes
0answers
106 views

Query Posts Via WordPress URL

I wanted to learn more about querying post types and their custom fields in WordPress. I've got two questions... I've followed this tutorial on Advanced Custom Fields and am trying to understand what ...
8
votes
1answer
301 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 ...
5
votes
3answers
814 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 ...
0
votes
2answers
51 views

WP Query - Is this correct?

Trying to debug, getting headache so I want to ensure that I have placed the query args in the correct place. I want to sort/order all my posts based on "myvalue". if ( have_posts() ) : /* Start ...
0
votes
1answer
2k views

How to create/modfiy WP_Query to search in post title OR custom field?

I need to modify or create a WP_Query that will search for a search term in both the post title OR a custom field (called 'my_field'). I have been reading and trying for hours, but I am right back to ...
0
votes
1answer
266 views

Filtering custom post type on a combination of custom taxonomies and custom fields?

I have a custom post type "artist". It has an associated custom taxonomy "artist_type" with terms "voice", "actor", "corporate" An "artist" also has custom fields for gender, location, agerangefrom ...
0
votes
0answers
252 views

Unable to use meta_query between currency values when value is over 1 million

I am trying to add a meta_query that searches for values of the field price that are between two different values. As long as the values stay below $1 million it works great. However, as soon as one ...
1
vote
1answer
206 views

Query posts with numeric meta values within a given range

I'm building a rental agency's website with WordPress. I'm having difficulties finding a good way to store an apartment's availability in meta fields. Specifically, enabling visitors to find ...
0
votes
1answer
31 views

Order by meta value

I've a custom post type that has a custom filed called deck-number and client wants to sort the result by deck number. FYI, deck numbers are numeric values. So I used query like bellow. ...
1
vote
2answers
152 views

WordPress Core - Optimizing meta_query generated SQL?

I have a problem in a plugin of mine which uses post meta to store ownership of a post. Basically, my issue is that the WP_Meta_Query class generates one JOIN per meta_query query. I don't understand ...
0
votes
1answer
197 views

how to make URL link query string

I have pages with a custom meta field called "ctr_state", and it contains a state name, like "Arizona". I am trying to construct a hyperlink that will return an archive-like list of pages that match ...
0
votes
1answer
340 views

Time sort with meta_key using UNIX timestamp failing due to date differences

I'm dealing with the following issue trying to sort a custom post type by a meta key created using the Advanced Custom Fields plugin Date and Time Picker add-on. The add-on creates a jQuery datepicker ...
0
votes
1answer
504 views

Check for the existence of custom field

I am using the Advanced Custom Fields plugin, and I want to do a query to show all posts where a "date" field is before today and where another custom field (a report) has a value. For now I have ...
0
votes
1answer
63 views

Sort Posts with custom meta key by default which is currently set as optional

I'm new to Wordpress so please bear with me. Please check this link The posts are currently sorted by date. But if you mouse over on Latest Articles you see there are other options for sorting like ...
0
votes
0answers
78 views

Meta_query weird behaviour

I have a custom field called date_from. Dates are stored in the yymmdd format (eg 20131104). When I use a meta_query to find posts in a specific date range the query works as expected, but when I use ...
0
votes
0answers
128 views

Why is WP_Query's meta_query not filtering results?

I am working on a wordpress site that utilizes WP_Query to find songs based on their category, tags, and other things in a tax_query, but it also groups in a meta_query which (should) find songs based ...
0
votes
1answer
115 views

Including 'cat' => $cat breaks meta_query

so, i have a custom loop that seems to be working everywhere but one place. $args = array( 'post_type' => 'post', 'meta_key' => 'wpcf-post-weight', 'orderby' => ...
0
votes
1answer
31 views

WP Query / Meta Query [duplicate]

How can I use a meta query like this: >>>>>> KEY_X Conditional IS ABSOLUTELY REQUIRED <<<<<<<<<< array( 'key' => ...
0
votes
0answers
30 views

How to create a link for wordpress meta datas?

I would like to create a link for "Leave a comment", which name "quick comment" (here come a ajax comment form on div). How can I do this? I have attached a picture where I'd like to put this link: ...
0
votes
0answers
109 views

Trying to combine multiple Wordpress queries

I am trying to query multiple post types and meta values in Wordpress... the query is trying to fetch event post types with a featured meta key, as well as post post types with the featured image set. ...
1
vote
2answers
101 views

Help on multiple meta_query

I am trying to fetch from the WP database posts with two meta_key values, but the result is 0 posts. Print out of the arguments: Array ( [taxonomy] => cardstax [term] => christmas ...
0
votes
1answer
50 views

using post_type with meta_query

I'm setting up a basic slideshow and want to loop through the custom post type “Projects” and display only projects with a photo attached - <ul class="slides"> <?php $args = array( ...
0
votes
2answers
131 views

comment meta_query for keys that aren't yet set

I need query help! I am trying to set up a meta_query (for get_comments) for keys that aren't yet set. I have some code that allows moderators to add a custom meta key to individual comments. Click ...
0
votes
1answer
107 views

Meta Query for specific months

I have a custom field which stores a date in a timestamp. I want to run a query that display posts based on the month, for example all entries from March, the specific day or year doesn't matter. I'm ...
0
votes
0answers
65 views

Meta query “OR” comparison not working as expected with array

I have this code to get cars that have color 1 or 0 ( stored in db in rw_color as 1 for white and 0 is black): $args_search = array( 'post_type' => array( 'cars' ), ...
0
votes
2answers
58 views

meta_query compare not doing what I want it to do

I'm trying to run a query that only shows posts if it's meta value has a date string that is LESS than the current date's string. An example is below; <?php $current = date('Ymd'); // Eg: ...
0
votes
1answer
131 views

latitude/longitude meta_query

I've been trying to figure out a way to do radius search in WP and decided upon a simpler way than big queries, I'm having problems returning results though I've got a function called ...
0
votes
1answer
32 views

How to output meta_key in wp_postmeta?

I have a meta_key in wp_postmeta called _su_description. How do I output its value?
0
votes
1answer
288 views

Can't sort order of wp_query with 2 meta keys

I'm trying to display custom post types by excluding the sold ones but also by displaying them in alphabetical order from the county meta_key. I'm trying to use pre_get_posts but I'm not sure that ...
0
votes
1answer
1k views

exclude custom post type by meta key in wp_query

I'm trying to display a custom post type (properties) and exclude posts that have a certain meta value (sold). Is there a way that I can do this? I have this for my code so far: ...
0
votes
1answer
117 views

Ordering a mysql style datetime stamp with meta_query

I have a custom post type field that I am storing data in called football_game_datetime. Example format and values for this field are examples like: "2013-10-31 14:00:00", "2013-09-16 20:00:00", ...
0
votes
1answer
970 views

meta_query with array as value with multiple arrays

Already got some clues on how to do this, see here: meta_query with array as value but i am confused over multiple meta_queries like this: for ($i=0; $i< count($amenities); $i++) { ...
2
votes
1answer
149 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 ...
1
vote
1answer
449 views

How do I create my own nested meta_query using posts_where / posts_join?

Some of my posts (not all) have a price as a meta key/value. Today I use the pre_get_posts action so that my users can search for prices that are between a certain value. This is the code that I'm ...
0
votes
1answer
287 views

Creating arguments from loop for WP_Query meta_query

I'm trying to create a WP_Query with the outcome arguments such as: $args = array( 'post_type' => array( 'post', 'custom' ), 'meta_query' => array( 'relation' => 'AND', ...