WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] pagination isshu with showing posts from custom post types category (5 posts)

  1. sdesigns
    Member
    Posted 11 months ago #

    I want to have a page that shows post from 3 different post types categories which I am able to do but the pagination is not working . I probably missed something in my code could someone please help me out.
    Thank you

    <?php
    
    $myquery['tax_query'] = array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'category',
            'terms' => array('gear-reviews'),
            'field' => 'slug',
        ),
        array(
            'taxonomy' => 'outtake_category',
            'terms' => array('gear-reviews'),
            'field' => 'slug',
        ),
    	array(
            'taxonomy' => 'story_category',
            'terms' => array('gear-reviews'),
            'field' => 'slug',
        ),
    
    );
    query_posts($myquery);
    
    ?>
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            							<div class="metadate"><?php the_time('l, F j, Y') ?></div>
    
    <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    <div id="featuredimage">
    
    <?php
    if ( has_post_thumbnail()) {
      echo '<a href="' . get_permalink($post->ID) . '" >';
      the_post_thumbnail();
      echo '</a>';
    }
    ?><!-- end featured image --></div>
    					<div class="entry">
                        <?php the_excerpt(); ?>
    
    					</div>
                                     <br class="clearfloat" />
    
    				</div>
    
    	<?php endwhile; ?>
    
    <?php wp_pagenavi(); ?>
    
    	<?php else : ?>
    
    		<h2>Not Found</h2>
    
    	<?php endif; ?>
  2. hz-ar
    Member
    Posted 11 months ago #

  3. sdesigns
    Member
    Posted 11 months ago #

    Thank you for the info. I looked at this and added the pagination info to the code but it still does not work. It is showing there is a second page of posts wich is the right number of them but when I click on it the posts are the same as on the first page. My guess is that I am missing somthing in my code any help would be great as I have been stumped on this for days now. Thank you

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $myquery['tax_query'] = array(
        'relation' => 'OR',
        array(
            'taxonomy' => 'category',
            'terms' => array('outdoor-recreation'),
            'field' => 'slug',
        ),
        array(
            'taxonomy' => 'outtake_category',
            'terms' => array('outdoor-recreation'),
            'field' => 'slug',
        ),
    	array(
            'taxonomy' => 'story_category',
            'terms' => array('outdoor-recreation'),
            'field' => 'slug',
        ),
      'paged' => $paged
    );
    query_posts($myquery);
    
    ?>
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
            							<div class="metadate"><?php the_time('l, F j, Y') ?></div>
    
    <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
    
    <div id="featuredimage">
    
    <?php
    if ( has_post_thumbnail()) {
      echo '<a href="' . get_permalink($post->ID) . '" >';
      the_post_thumbnail();
      echo '</a>';
    }
    ?><!-- end featured image --></div>
    					<div class="entry">
                        <?php the_excerpt(); ?>
    
    					</div>
                                     <br class="clearfloat" />
    
    				</div>
    
    	<?php endwhile; ?>
    
    <?php wp_pagenavi(); ?>
    
    	<?php else : ?>
    
    		<h2>Not Found</h2>
    
    	<?php endif; ?>
  4. keesiemeijer
    moderator
    Posted 11 months ago #

    Try to query like this:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
      'paged' => $paged,
      'tax_query' => array(
        'relation' => 'OR',
        array(
          'taxonomy' => 'category',
          'terms' => array( 'outdoor-recreation' ),
          'field' => 'slug',
        ),
        array(
          'taxonomy' => 'outtake_category',
          'terms' => array( 'outdoor-recreation' ),
          'field' => 'slug',
        ),
        array(
          'taxonomy' => 'story_category',
          'terms' => array( 'outdoor-recreation' ),
          'field' => 'slug',
        ),
      )
    );
    query_posts( $args );
  5. sdesigns
    Member
    Posted 11 months ago #

    Thank you that did it.

Reply

You must log in to post.

About this Topic