0

I have create a loop with a custom query. This query contains a php parameters that i m getting from url with GET method. The problem is that the pagination (even if it counts the posts correct at first page) is not working correct. I 'm getting 404 error at second page. This the code at my loop page:

$cat = get_queried_object();
echo '<h1 class="childcatdes">'. $cat->name . '</h1>';
echo '<p class="childcatdescr">'. $cat->description . '<br><br></p>';
do_action( 'woocommerce_before_single_product' );

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


$product_args = array(
    'post_type' => 'product',
    'posts_per_page' => $posts_per_page,
    'paged' => $paged,
    'page' => $paged,
    'tax_query' => array(
         'relation' => 'AND',
        array(
          'taxonomy' => 'product_cat',
          'field'    => 'name',
          'terms'    => $cat->name,
        ),
        array(
          'taxonomy' => 'manufacturers',
          'field'    => 'slug',
          'terms'    => $_GET['filter_manufacturers'],
          'operator' => 'IN'
        )
    ),
    'orderby' => 'name',
    'order' => 'ASC',
);

$custom_query = new WP_Query( $product_args );

if($custom_query->have_posts()) {
    echo '<ul';
    while ($custom_query->have_posts() )  : $custom_query->the_post(); 
        echo '<li>';
            $link = get_the_permalink();

            echo '<a href="' . $link . '">' . get_the_title() . '</a>';

        echo '</li>';
    endwhile;


    echo '</ul>';
}
else {
    echo 'No post found.';
}
?>
<nav class="pagination">
    <?php pagination_bar( $custom_query); ?>
</nav>  

And i use this code to my functions.php file for the function pagination_bar

function pagination_bar( $custom_query) {
    $total_pages = $custom_query->max_num_pages;
    $big = 99999;
    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));

        echo paginate_links(array(
            'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%',
           'current' => $current_page,
           'format' => 'page/%#%/',
           'total' => $custom_query->max_num_pages,
           'add_args' => array(
               'filter_manufacturers' => $_GET['filter_manufacturers'],
           )
        ));
    }
}

All off these are working properly when i don't use taxonomy manufacturers at product_args.

Please advice

0

Finally i had create a taxonomy with name manufacturers and an attribute with the same name. This may caused a confict (i didn't find out more!). So i create an attribute with name brands and i use this for my custom query.

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.