Paginated Taxonomy Term Archive including one post per term

As discussed in chat and as @Rarst already told you, there’s no default WordPress way to accomplish Archive of multiple taxonomies and all their terms In fact there’s no way to accomplish Archive of single taxonomy and all its terms in WordPress. Simply because WordPress doesn’t do that – without custom SQL queries. But there’re … Read more

Transient caching for wp query

For my WordPress testimonials widget plugin I’ve successfully used transients with expiration dates to drop page loads by 0.1 to 0.5 seconds. Using WordPress’s own transients is a life-saver. It’s so much easier to package or use straight as needed and then concentrate again on application logic. Rolling yet another caching system is useless. Further, … Read more

So strange result of wp_query and have_posts

If we look at have_posts() in source, we can see why this happens: function have_posts() { if ( $this->current_post + 1 < $this->post_count ) { return true; } elseif ( $this->current_post + 1 == $this->post_count && $this->post_count > 0 ) { do_action_ref_array(‘loop_end’, array(&$this)); // Do some cleaning up after the loop $this->rewind_posts(); } $this->in_the_loop = … Read more

Show most popular post of last 12 months

Just as @Rarst suggested, you must have your $args defined within your function. You could solve it by using global variables, but we don’t want too many such variables flying around! Check out the PHP docs on the scope of a variable or write your code in a class. You can also simplify your query. … Read more

WP_Query tax_query problem

Found problem. I replaced: $posts = $query->get_posts(); with: $posts = array(); if ($query->have_posts()){ while ($query->have_posts()){ $query->next_post(); array_push($posts, $query->post); } } And everything is working now.

WP query exclude post within the last month / only show over 1 month old

The date query for WP_Query supports several options, including before and after. Using just before, you can fetch posts from before a certain date (excluding posts from that date on): $args = array( ‘date_query’ => array( array( ‘column’ => ‘post_date_gmt’, ‘before’ => ‘1 month ago’ ) ), ‘posts_per_page’ => -1, ); Furthermore, you can specify … Read more