Array Chunks and Inserting Varying HTML in WP_Query

That’s a pretty complicated approach you’re taking. Why not simply add a counter? Like this: $i=1; echo ‘<div class=”row full”>’; if( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); if ($i < 3) $class = “large-6 medium-6 small-12 columns” else “large-4 medium-4 small-12 columns”; echo ‘<div class=”‘ . $class . ‘”>’ … output your … Read more

Is temporarily overwriting $wp_query a bad idea?

In general, I agree with Howdy_McGee that one should avoid overwriting the main query unless absolutely necessary – more often than not, modifying the main query with something like a ‘pre_get_posts’ hook is a better solution to such scenarios. Manually overwriting the global $wp_query can cause all sorts of unintended behaviors if you are not … Read more

meta_key and meta_value not working together

You could try this: $args = array( ‘post_type’ => ‘cqpp_interventions’, ‘posts_per_page’ => ‘-1’, ‘meta_query’ => array( array( ‘key’ => ‘priority’, ‘value’ => ’80’ ) ) ); The real issue with your query is because you are passing meta_key and meta_value. However, the arrays in your meta_query argument should have the keys key and value instead. … Read more

Intentionally exceed max_num_pages on main query without getting 404?

On every page load, WordPress executes these functions in their respective order: init(); parse_request($query_args); send_headers(); query_posts(); handle_404(); register_globals(); where the main query is finished after query_posts(). Note that in this point in time, WordPress knows the template AND all the query variables like max_num_pages. In handle_404(), if the main query has any posts, the function … Read more

tax_query shows no results if nothing is selected

So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more

How to detect custom query inside `posts_where` hook?

If we have the query arguments like this $args = array( ‘queryid’ => ‘blackjack’, … ); $q = new WP_Query( $args ); Note we added one custom query argument that is not officially present in here. Now we can identify the exact query by that queryid if we use the second parameter of the posts_where … Read more