apply custom where to the default $wp_query

The posts_where filter should still fire. Just add it like this: function homepage_load_posts($query) { if ($query->is_home()) { add_filter( ‘posts_where’, ‘filter_where’ ); // And make the filter self-removing… // Create a new filtering function that will add our where clause to the query function filter_where( $where=”” ) { remove_filter( ‘posts_where’, ‘filter_where’ ); // posts 30 to … Read more

Get posts from multiple tax terms

I honestly don’t see how that works at all since get_the_term_list returns an HTML string. First, you need get_the_terms and wp_list_pluck. Second, you need a tax_query. That {tax} = {term} pattern is deprecated. $this_post = $post->ID; $args = array( ‘post_type’ => ‘dir_entry’, ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post__not_in’ => array($this_post), ); … Read more

WP_Query array key / value pairs?

Is there a list of the keys that can be used here. Is there a name for these key / value pairs. The “list” is in the Codex on the WP_Query page or you can just check the source. I don’t know what kind of “name” you are looking for. Other that “key/value” I’d call … Read more

Multiple Rows in a using wp_query

Get all of your posts in one query, then count the iterations of your loop. Pseudo-code follows. if ( $query->have_posts() ) { $i = 0; while ( $query->have_posts() ) { // If $i is 5 (5th post), end one row and start the next if (++$i == 5) { echo ‘</tr><tr>’; } // the rest … Read more

Event with multiple dates, display events chronologically

Here you go, explanations as comments // setup array to store things in while we loop $events_out = array(); // assume you already have your loop built the way you want while($loop->have_posts()) : $loop->the_post(); $instances = array(); // grab meta dates $instances[] = get_post_meta($post->ID, ‘dateA’, true); $instances[] = get_post_meta($post->ID, ‘dateB’, true); $instances[] = get_post_meta($post->ID, ‘dateC’, … Read more

How to use if($wp_query->query_vars[‘name’] == ‘pagethatdontexist’) without getting a 404? How to suppress 404

You can use an earlier action, request, to do whatever you need. It allows you to modify query variables, or even cancel the entire request without issuing a 404 error: function wpse112929_cancel_request_parsing( $query_vars ) { if ( in_array( ‘pagethatdontexist’, $query_vars ) ) { return array(); } return $query_vars; } add_action( ‘request’, ‘wpse112929_cancel_request_parsing’ ); I used … Read more

Query Posts by Tag and exclude

It seems you’re looking for the tag parameters: $args = array( ‘posts_per_page’ => 5, ‘tag’ => ‘YOUR-TAG-SLUG’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ); $query = new WP_Query($args); while ($query->have_posts()) : $query->the_post(); … endwhile; // don’t forget to reset/restore the query wp_reset_postdata();

WordPress Custom Search Form Displaying Unexpected Results

You are likely getting unexpected results due to your query string. I would recommend getting familiar with the following: List of WordPress Query Variables WordPress function: get_query_var($var); List of WordPress Reserved Terms. Reserved Terms Avoiding the following reserved terms is particularly important if you are passing the term through the $_GET or $_POST array. Doing … Read more