我创建了一个查询,该查询工作正常,并正确显示分页。但是,当单击链接/产品/类别/应用范围/页面/2时,页面将加载并返回到/产品/类别/应用范围/而不是第2页,有什么原因吗?
$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);
SO网友:Sven
也许你可以看看this question and the answers 并检查是否确实要使用query_posts()
因为在处理POST分页时,不建议这样做。为什么不使用pre_get_posts 改为采取行动?或者您可以尝试以下方式:
<?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
));
?>