Articles of meta query

Custom query with DECIMAL(5,2)

I want to know if there is a way to DECIMAL (5,2) instead of DECIMAL in meta_query

Get Posts shortcode plugin and meta_query?

I’m using Get Posts plugin to list posts with post type “project”. I want to filter the list by two custom fields: year (ex. 2006) and state (ex. Completed). I added meta_query to the plugin’s get_post args and tried the shortcode: [get_posts post_type=”project” meta_query=”array(array(‘key’ => ‘state’, ‘value’ => ‘Completed’),array(‘key’ => ‘year’,’value’ => ‘2006’))” suppress_filters=”false”] This […]

meta_query, number comparison, not quite working as it should

I have a wp_query that gets all custom post types in ascending order from today, to list some events on a site of mine. While this works fine: $args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 5, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘my_special_date’, ‘meta_value’ => date(‘Ymd’,strtotime(“today”)), ‘meta_compare’ => ‘>=’ ); I am […]

Displaying posts with only upcoming dates according their custom field date value

I got posts that have starting date as a custom field value. I’m displaying few of those posts in my sidebar in ascending order so that the post with closest starting date is shown first. This is what I have and it works great: <?php query_posts(‘&post_type=events&posts_per_page=5&meta_key=start_date&orderby=meta_value&order=asc’); ?><?php while ( have_posts() ) : the_post(); ?><li><span class=”eventtext”><?php […]

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 ‘OR’ query, the ‘NOT EXISTS” portion is ignored and the query returns every post […]

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( ‘relation’ => ‘AND’, array( ‘key’ => ‘minbeds’, ‘value’ => $rooms, ‘compare’ => “<=”, ‘type’ => ‘numeric’ ), array( ‘key’ => ‘maxbeds’, ‘value’ => $rooms, ‘compare’ => “=>”, ‘type’ => […]

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] => Array ( [key] => price [value] => 1000 [type] => numeric [compare] => <= ) [1] => Array ( [relation] => OR [0] => […]

Possible to create a permalink to sort with meta_key?

I feel like I’ve been all around the web and back again looking for an answer to this and it’s really starting to grind my gears. Not sure if this is the correct way to do it, but I want to add a query_posts array to a URL in the form of a query_arg. This […]

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 for the genres and moods it seems (i.e. I don’t need to modify pre_get_posts), but I can’t limit posts to only those […]

How to order a post type with meta_value_num and if meta_value_num does not exist then order by date

I want to order a list of post on basis of ratings. I have used meta key “wp_ratings” for storing the rating value in wp_postmeta table. Now I want to sort all posts . If a post does not contains the meta key , then sort it with date. $args = array( ‘post_type’ => ‘recipe’, […]