How to get all post except particular category without breaking the paging

I would filter pre_get_posts. Perhaps like so, though you may need to tweak the conditional a bit: function wpse71508_filter_pre_get_posts( $query ) { if ( is_main_query() ) { if ( is_home() || is_archive() ) { $query->set( ‘cat’, ‘-22’ ); } } return $query; } add_action( ‘pre_get_posts’, ‘wpse71508_filter_pre_get_posts’ ); If you could clarify the context (rather than … Read more

Problem with is_tax in WP_Query loop

The codex on is_tax: This Conditional Tag checks if a custom taxonomy archive page is being displayed. That is not the condition you want to check for. Take a look at the has_term function and use it like so: if( has_term( ‘tennis-ball’, ‘ball-types’, $post->ID ) ) { /* SHOW THE TENNIS BALL GRAPHIC */ } … Read more

2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?

Your two queries are identical, meaning you only need one of them. The basic solution is: global $testimonials; $testimonials = new WP_Query(array( ‘posts_per_page’ => 2, /* <– get both */ ‘post_type’ => ‘testimonial’, ‘post_status’ => ‘published’, ‘orderby’ => ‘rand’, ‘ignore_sticky_posts’ => true /* you need this to control post count accurately */ )); // header … Read more

Advanced WP Query and/or

I am not 100% sure what you are asking but as written that is going to be wrong. tax_query is an array of arrays but you have an array of array of arrays. You create the third array when you put $taxQuery into array($taxQuery). This should be more correct: $args = array( ‘post_type’ => $postType, … Read more

Ordering a mysql style datetime stamp with meta_query

‘orderby’ => ‘meta_value_num’ will try to force the value to a number by adding 0. In other words, “2013-09-30 22:00:00″+0 When I tested that both PHP and MySQL converted the string to 2013, which is not what you want. That particular date format, and only that date format, will sort correctly if you just leave … Read more

WP Query with multiple tags by get the tags

If you read the Codex entry, you must pass an array as tag_slug__in. In this case though, I would use tag__in with IDs rather than slugs: $tag_ids = array(); foreach( get_the_tags($post->ID) as $tag ) { $tag_ids[] = $tag->term_id; } $recent_posts = new WP_Query( array( ‘tag__in’ => $tag_ids, ‘posts_per_page’ => 2, ‘cat’ => 20 ) );

Query Vars Not Set in Main Query

Query vars are… fun like that. Depending on which archive you are messing with get_post_type() just might be simple enough to do it (it gets type from actual post, not query). Otherwise you might want to go for get_queried_object() to figure out what precisely you are dealing with.

Using Wp_Query without the loop?

The query itself doesn’t change globals, however you are correct that the_post() does. The most contained way to just retrieve posts (as array of results) is using get_posts() function, which is wrapper around WP_Query and takes same arguments.

Problem with WP_query

Your second block of code is strange. The use of query_posts() doesn’t really make sense. I don’t even know what that is intended to do. Additionally, that is not really the best way to exclude posts from a Loop, and is what is causing your 5 vs. 6 posts issue. You need to exclude the … Read more