0

I have created a query which work correctly and displays the pagination correctly. However when clicking the links /products/category/application-range/page/2 the page will load and go back to /products/category/application-range/ rather than page 2, is there any reason why?

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'connected_type'      => 'product_to_category',
  'connected_items'     => $post,
  'posts_per_page'  => 10,
  'paged'           => $paged,
  'post_parent'     => 0,
  'orderby'         => 'menu_order',
  'order'           => 'ASC'
);

$products = query_posts($args);
1

Perhaps you can take a look at this question and the answers and check if you really want to use query_posts() as it is not recommended while dealing with posts pagination. Why not use pre_get_posts action instead? Or you can try something like this:

<?php

    $custom_query = new WP_Query(array(
        'post_status' => 'publish',
        'post_type' => 'products',
        'connected_type' => 'product_to_category',
        'connected_items' => $post,
        'order' => 'ASC',
        'order_by' => 'menu-order',
        'posts_per_page' => '10',
        'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
    ));

?>

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.