Manipulating a query

You might try to add a posts_where filter in your pre_get_posts hook: function my_pre_get_posts( $q ){ if( $q->is_main_query() ) add_filter( ‘posts_where’, ‘my_posts_where’ ); return $q; } ! is_admin() && add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); where function my_posts_where( $where ){ // your custom replacements on the $where string // … // remove the filter remove_filter( current_filter() , … Read more

meta_query compare not doing what I want it to do

Your code looks valid for me. The only thing you can try is ‘NUMERIC’ instead of ‘numeric’ and to cast $current to int as date() will return a string. $current = (int)date(‘Ymd’); To debug this further you can place this directly under your code: global $wpdb; var_dump( $wpdb->last_query ); You’ll then have the complete query … Read more

wp_query conditionally get posts

You can check if a query has posts with if( $your_query->have_posts() ), and only output the container if it passes that test. $featuredPosts = new WP_Query( array( ‘posts_per_page’ => 2, ‘cat’ => 6, ‘offset’ => 4 ) ); if ( $featuredPosts->have_posts() ) : echo(‘<ul class=”right-hang”>’); while ( $featuredPosts->have_posts() ) : $featuredPosts->the_post(); endwhile; echo ‘</ul>’; endif;

Pagination With Custom WP Query not functioning

One issue at least: you’ll want to close the loop before outputting your pagination links, or else they’ll be output on every iteration of the loop. But you’ve got paginate_links() before endwhile;. Try this arrangement instead: // open loop if ( have_posts() ) : while ( have_posts() ) : the_post(); // Loop markup // close … Read more

Including ‘cat’ => $cat breaks meta_query

Not sure why this works, where the other query was failing. I’m not sure if it’s a bug that others are experiencing or not. Anytime I included any category “inclusive” arg, it broke my meta_query, but it didn’t seem to if i was “excluding” categories. So,…making an array of all category ids, then unsetting the … Read more