Randomly placed sticky custom posts complemented by blog posts

This did it: $products = get_posts(array(‘post_type’ => ‘products’)); $numbers = range(0, 8); shuffle($numbers); $x = 0; foreach($products as $post) : setup_postdata($post); $product = new WP_Query(array(‘p’=>$post->ID,’post_type’=>’products’)); if (!empty($product->posts)) array_splice($posts,$numbers[$x],0,$product->posts); $x++; endforeach; foreach($posts as $post) : setup_postdata($post); …

loop query exclude meta_key with meta_value

Do NOT use query_posts() – it is bad, very bad to be exact. For more information read: When should you use WP_Query vs query_posts() vs get_posts()? When to use WP_query(), query_posts() and pre_get_posts Use WP_Query instead. Example with meta_key, meta_value and meta_compare parameters in use: $args = array( ‘meta_key’ => ‘clpr_excoupon’, ‘meta_value’ => ‘0’, ‘meta_compare’ … Read more

Too many nested wp_query loops in this hypothetical query?

When you need to retrieve and present a lot of information there is bound to be complexity. Mostly it is finding right balance between complex querying and complex sorting in PHP (which is often overlooked option). Your logic looks mostly fine, what could use tweaking as for me: Genre seems more like a taxonomy than … Read more

Alter secondary loop to exclude posts from current page category

This one is even more simple. Refer to the WP_Query() category parameters. I think you will want to use ‘category__not_in’. foreach ( $random_posts_cat_array as $random_post_cat ) { if ( $post_cat_slug == $random_post_cat ) { // No posts from this category! $random_posts_query_args[‘category__not_in’] = $post_cat_id; } } Edit So for example if a post is currently on … Read more

Display page of custom posts?

I think your problem is in the exact code that you’ve mentioned. pre_get_post is a bastard if you don’t use it correctly. With any archive type conditions used in pre_get_posts, it will affect both front end and back end. This include archives pages, category and taxonomy pages, tag pages and author pages. You’ll need to … Read more

Display different number of posts from one category on the different pages

You can check for the existence of a variable, so you don’t overwrite it: add_action( ‘pre_get_posts’, ‘wpse7262_pre_get_posts’ ); function wpse7262_pre_get_posts( &$wp_query ) { if ( $wp_query->is_category() ) { if ( ! array_key_exists( ‘post_type’, $wp_query->query_vars ) ) { $wp_query->set( ‘post_type’, ‘game’ ); } if ( ! array_key_exists( ‘posts_per_page’, $wp_query->query_vars ) ) { $wp_query->set( ‘posts_per_page’, 9 ); … Read more