Loop for custom post types filtered by a taxonomy

I’ve figured out the answer using the WordPress forum. Solution below: <?php query_posts( array( ‘country’ => ‘event-england’ ) ); ?> <?php if( is_tax() ) { global $wp_query; $term = $wp_query->get_queried_object(); $title = $term->name; } ?> <ul> <span class=”tax-title”><?php echo($title); ?></span> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/17046/<?php … Read more

WP_query exclude posts of a format

tax_query takes an array of arrays. Try this: $myposts = new WP_Query(array( ‘tax_query’ => array( array( ‘taxonomy’ => ‘post_format’, ‘field’ => ‘slug’, ‘terms’ => array(‘post-format-quote’), ‘operator’ => ‘NOT IN’ ) ), ‘posts_per_page’ => 3 ) ); Further reading: http://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/

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