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();

Trouble with pagination

You appear to be trying to paginate the $all_work query data, but your pagination code is using the $wp_query data… global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1, get_query_var(‘paged’)); … for reasons unknown to me. If you want to paginate $all_work you need to use the $all_work data. The data in … Read more

Exclude taxonomy term from all loops, but having it on widget

Looks like you’ve excluded a taxonomy term, not the whole taxonomy. Is that what you intended? But on to the answer… Right before your query in the widget add: remove_action( ‘pre_get_posts’, ‘exclude_category_posts’ ); And then you probably want to put it back again after that query by repeating: add_action( ‘pre_get_posts’, ‘exclude_category_posts’ ); That is a … Read more

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

WP_Query within function within WP_Query

Using wp_reset_query() really just makes sense if you are using query_posts(), which you don’t need and shouldn’t do – see When should you use WP_Query vs query_posts() vs get_posts()? . This means you should go with WP_Query and wp_reset_postdata() instead. Besides that you should give your custom, secondary queries a object, name differing from $query … Read more