0

I've had a problem with this for quite some time now and cannot for the life of me figure it out. I am using Multi-site and not sure if that has anything to do with it or not, so keep that in mind.

Problem:

When clicking on tags on a post or custom post type, I only get the default post count set by WP which is 10 posts as results. Pagination shows at the bottom for next post and older posts, but when I click on either link, page 2 is not found and it sends me to 404 page. There is a mix of regular posts and then custom posts types that should be showing, but regardless the post type, it only shows 10 even though there are hundreds.

At first I was using the Twentyten way of showings tags which was using get_template_part() and redirecting to a loop.php page. I have sense eliminated that process and created my own tag.php page and use the default wordpress loop to query for posts.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

However I had to use this bit of code to query for all posts types and not just the regular ones.

global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => array('post, cool_tools, tribe_events') ) );
query_posts( $args );

My pagination code for the page reads :

<div id="nav-below" class="navigation">
    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
    <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
</div><!-- #nav-below -->

The url to the missing page is:

/tag/tagname/page/2/

Can anyone tell me why WP wont find any more tags?

**Update

As per Chip's example, here is how I have it setup now.

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;

$args = array(
    'post_type' => 'post',
    'tag_slug__and' => $tagname,
    'paged' => $paged
);

$query = new WP_Query($args);

if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();

Yet when I click newer posts at the bottom, it still takes me to a 404 page and no page 2 found for tags.

3

The problem is query_posts(). It is stomping on the default query, and killing your pagination. Don't use query_posts(). Filter $wp_query at pre_get_posts instead:

function wpse123674_pre_get_posts( $query ) {
    // Only modify the main query on the tag archive index
    if ( $query->is_main_query && $query->is_tag() ) {
        $query->set( 'post_type', array('post, cool_tools, tribe_events') );
    }
}
add_action( 'pre_get_posts', 'wpse123674_pre_get_posts' );

This belongs in functions.php. In your template file, simply remove all references to any query modification.

0

I also advise, to click "PERMALINKS --> SAVE" once again, to reflush cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.