When to add_filter() to Custom Query

You want to add your filter before you create the query: add_filter( ‘posts_join’, ‘custom_posts_join’ ); $test = new WP_Query( $args ); where you can define the filter callback in your theme files, for example functions.php or in a plugin: function custom_posts_join( $join ) { // modifications // $join = … // remove the filter remove_filter( … Read more

How to orderby meta_value_num with dollar ($) sign

You could also use the posts_orderby filter: function wpse155827_posts_orderby_price( $orderby ) { return str_replace( ‘wp_postmeta.meta_value’, ‘substr(wp_postmeta.meta_value, 1)’, $orderby ); } add_filter( ‘posts_orderby’, ‘wpse155827_posts_orderby_price’ ); $theQuery = new WP_Query( array( ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘price’, ‘order’ => ‘ASC’, ‘suppress_filters’ => false, ) ); remove_filter( ‘posts_orderby’, ‘wpse155827_posts_orderby_price’ );

WP Query Exclude and Start by Menu Order Offset

You can use offset to number of post to displace or pass over. Like this. $args = array( ‘post_type’ => ‘my-post-type’, ‘posts_per_page’ => 3, ‘order_by’ => ‘menu_order’, ‘offset’ => ‘3’, ‘order’ => ‘ASC’ ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post();

Splice together 2 WP_Query objects

I’m not sure I understand the question, but if you just wan’t do display something from resultset B on every nth iteration, you could use next_post() or simply call the_post() on the second query object. Of course you also need to check so there’s enough items left in the result and so on: $query1 = … Read more

current_post not working – give me -1 for every post

What you are seeing is totally expected as you are trying to get the value of $current_post outside the loop. Before and after the loop, the value of $current_post will always be set to -1. To get the proper value, you need to check $current_post inside the loop, the first post will be 0 and … Read more

What format does the meta_query TIME type require?

Date and time format meta_query requires the same format you used when storing the data of the meta fields. Some times different formats can be compared directly, but most of the time they aren’t. A recommend format to use is MySQL format: date format: YYYY-MM-DD (for PHP date functions: Y-m-d) time format: HH:MM:SS (for PHP … Read more

WP_Query returning no results

you might also need to set the ‘post_type’ in $the_args, and possibly the ‘posts_per_page’; http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters example: // WP_Query arguments $the_args = array ( ‘post__in’ => $results, ‘post_type’ => array( ‘any’ ), ‘posts_per_page’ => 10 );