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

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

Create a Blog Template Page

Why reinvent the wheel? Just create archive-{posttype}.php, and ensure that ‘has_archive’ is set to true for the post type. If your post type is event: archive-event.php. Then, WordPress will handle the query automatically. If pretty permalinks are enabled: example.com/{posttype} …will display the archive index page for {posttype}.

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