0

The following loop gets all posts within a relevant category. It does generate a pagination URL, but it does not take me there (it just redirects back to the homepage).

Would anyone know why?

$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$category_cat_args =
    array(
    'category_name' => $current_category,
    'posts_per_page' => 2,
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'date',
    'order' => 'DESC',
    '&paged' => $paged
);
$wp_query = new WP_Query( $category_cat_args );
?>
<div class="category-page">
    <div class="col68-2r">
        <h1 class="post-title">
        <?php echo $current_category; ?> news</h1>
        <?php
        if ( $wp_query->have_posts() ):
        while ( $wp_query->have_posts() ):
        $wp_query->the_post();
        $images = get_field( 'gallery' );
        if ( $images ):
        ?>
        <div class="col33">
            <div class="img-ctnr">
                <a href="<?php the_permalink();?>">
                <img src="<?php  echo $images[0]['url'];?>" alt="example-image">
                <?php bottom_note(); ?>
                </a>
            </div>
        </div>
        <?php
        endif;
        endwhile;
        else: echo "There are no posts in this category";
        endif;
        ?>

        <?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>

        <div class="clear"></div>
        <?php if ( $wp_query->max_num_pages > 1 ) : ?>
        <a href="<?php  echo get_next_posts_page_link();  ?>" class="btn-ar"> more articles</a>
        <?php endif; ?>
    <?php wp_reset_postdata(); ?></div>
0
wp_pagenavi( array( 'query' => $wp_query ) ); change to wp_pagenavi($wp_query);

I think that $wp_query is the variable that you define! That is the thing you will need to insert! Sometimes, you will need to pass $wp_query->max_num_pages depend on your custom query request

1
  • Thanks, but that receives an error: CATCHABLE FATAL ERROR: OBJECT OF CLASS WP_QUERY COULD NOT BE CONVERTED TO STRING. And using wp_pagenavi($wp_query->max_num_pages); still just redirects me to the homepage. – tmyie May 14 '14 at 12:26

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.