0

I cannot get the <?php next_posts_link(); ?> working in my custom post loop on the first page ( website.com/news). The funny thing is that <?php previous_posts_link(); ?> does work on the second page (website.com/news/page/2/)

This is my query:

<div class="col-md-12">
    <h2>News</h2>   

<?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $the_query = new WP_Query( 'posts_per_page=6&paged=' . $paged ); 
?>

    <div class="row">   
        <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
            <div class="col-md-4">
                <div class="card">
                    <?php the_post_thumbnail(); ?>
                        <div class="card-body">
                            <h4><a class="newslink" href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
                            <p class="card-text">
        <?php    
        the_excerpt(40,the_date('j F, Y','','<br>'));?>
                            </p>
                 </div>
            </div>
    </div>
        <?php 
        endwhile;
        ?>
<?php next_posts_link(); ?>
<?php previous_posts_link(); ?>
<?php  wp_reset_query(); ?>
</div>

As far as I am concerned i'm using the global var $wp_query so I'm not sure why it isnt working for the first page.

  • Why are you using a custom query at all? – Jacob Peattie Jul 15 '18 at 12:30
  • Because I altered some of the standard items and some need future altering.Anysways if i use the wordpress example code as seen on: codex.wordpress.org/Pagination The problem is still there. – cero Jul 15 '18 at 12:48
0

Nvm I fixed it by using the a standard query:

    <?php 
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=6'.'&paged='.$paged);
?>

    <div class="row">   
        <?php while ($wp_query -> have_posts()) : $wp_query -> the_post(); ?>
  • Seems like I wasn't using the global var in the first example -.- – cero Jul 15 '18 at 13:01

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.