next_post_link / previous_post_link not working with WP_Query

next_post_link & previous_post_link work off the global $wp_query. You could simply overwrite the main query with $wp_query =& $query, or replace your custom query with the standard ‘global’ functions. <?php query_posts( array( “post_type” => “page”, “page_id” => $post->ID ) ) ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post() … Read more

Issue with front page navigation after upgrading to 3.4

It stopped to work with WP 3.4 because there was fixes to handle_404(), and You are using wrong way on homepage… instead of creating new query, modify main query. Changeset: http://core.trac.wordpress.org/changeset/19892 Sample code: function my_query_for_homepage( $query ) { if( $query->is_main_query() && $query->is_home() ) { $query->set( ‘post_type’, array( ‘post’, ‘gaming’, ‘entertainment’, ‘tech’, ‘breakroom’, ‘podcasts’, ‘off-grid’ ) … Read more

Exclude All Posts Which Do Not Have A Tag Assigned

here is an example loop.. you can change the number of tag to exclude based on the amount you want… <?php if (have_posts()) : while (have_posts()) : the_post(); // GET THE TAGS OF CURRENT POST IN LOOP AND COUNT THE AMOUNT $posttags = get_the_tags(); $howmany = count($posttags); if($howmany > 2) { ?> <h3><?php the_title(); ?></h3> … Read more

Pass $page_id to new WP_Query

If you’re on the same page and you just need to display the same page’s content again, you can just call the_content multiple times. To answer your question, however: You’ll use the page_id argument for WP_Query (you could also probably use p). You can even remove your global $wp_query and the like. <?php $new_query = … Read more

Transient api Caches confused

“This code works” – but it doesn’t! If you’re gonna cache paginated posts, you’ll need to store them chunked: if ( ! $my_paged = absint( get_query_var( ‘paged’ ) ) ) $my_paged = 1; if ( ! $my_query = get_transient( “recent_$paged” ) ) { $my_query = new WP_Query( “cat=3&posts_per_page=5&paged=$my_paged” ); set_transient( “recent_$paged”, $my_query, 60 * 60 … Read more

How do I rewrite this loop as a new WP_Query style-loop?

You’re 95% of the way there already. Just add if ( $my_query->have_posts() ) and incorporate your $odd variable: <?php $my_query = new WP_Query(‘offset=5&showposts=10’); if ( $my_query->have_posts() ) : $odd = false; while ($my_query->have_posts()) : $my_query->the_post(); $odd = !$odd; ?> <div class=”<?php if ($odd) echo ‘uneven ‘; ?>post”> <h3><a href=”https://wordpress.stackexchange.com/questions/70713/<?php the_permalink(); ?>”><?php the_title(); ?></a></h3> <?php the_excerpt(); … Read more