0

I am trying to list a set of products which match a taxonomy terms. The list of the products is fine, but I can't figure out the pagination of my custom posts. I have been looking for information in google, here, and many other places, with no results. I don't even know how to address this issue. My wordpress file is called: taxonomy-species-seefood.php This file is responsable for listing seefood animals and its code is:

<?php
 $paged = get_query_var('paged') ? get_query_var('paged') : 1;
$posts_per_page = 6;
$offset = ( $paged - 1 ) * $posts_per_page;

$args = array(
        'post_type'      => 'products',
        'post_parent' => '0',
        'tax_query' => array(
            array(
                'taxonomy' => 'species',
                'field'    => 'slug',
                'terms'    => 'seefood',
            ),
        ),
        'orderby'        => 'date',
        'order'          => 'DESC',
        'posts_per_page' => $posts_per_page,
        'post_status'    => array('publish', 'pending', 'draft'),
        'paged'          => $paged,
        'offset'         => $offset
    );

$myposts = new WP_Query($args);

    ?>


<div role="main" id="content" class="content-wrap">
    <div class="container">

        <div id="primary" class="content-area col-md-12 post-list">
            <?php
            echo '<main ';
            if ( $myposts->have_posts() ) {
                echo ' itemscope itemtype="http://schema.org/Blog" ';
            }
            echo ' id="main" class="site-main" role="main">';

            if ( $myposts->have_posts() ) {

                echo '<header class="page-header">';

                echo '</header>';
                echo '<div class="flex-items">';
                while ( $myposts->have_posts() ) {
                    $myposts->the_post();
                    /**
                     *  Include the Post-Format-specific template for the content.
                     *  If you want to override this in a child theme, then include a file
                     *  called content-___.php (where ___ is the Post Format name) and that will be used instead.
                     */
                    get_template_part( 'content', get_post_type() );
                }
                echo '</div>';
                wp_reset_postdata(); 
                wpbeginner_numeric_posts_nav($myposts);

            } else {
                get_template_part( 'content', 'none' );
            }
            ?>

The function wpbeginner_numeric_posts_nav($myposts) works fine and it has been taken from https://www.wpbeginner.com/wp-themes/how-to-add-numeric-pagination-in-your-wordpress-theme/

And I think my $args variable is correct, but no sure at all.

Any advice would be appreciated. I have got a bit of a block.

Thank you!

0

1 Answer 1

0

In the function wpbeginner_numeric_posts_nav($myposts) there was a mistake. So everything was fine. Thank you in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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