当我在我的网站上按类别搜索时,我试图更改页面。当我不在某个类别下搜索时,我可以很好地切换页面,但当我搜索某个类别时,我无法切换页面。
$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
        $orderby = ( get_query_var( \'orderby\' ) ) ? absint( get_query_var( \'orderby\' ) ) : \'display_name\';
        if($_GET[\'search\'] && !empty($_GET[\'search\'])) {
            $search = $_GET[\'search\'];
        }
        if($_GET[\'category\'] && !empty($_GET[\'category\'])) {
            $category = $_GET[\'category\'];
        }
        $args = array(
            \'orderby\' => \'rand\',
            \'number\' => 7,
            \'paged\' => $paged,
            \'search\' => \'*\'.esc_attr( $search ).\'*\',
            \'meta_query\' => array (
                array(
                    \'key\' => \'organization_category_2\',
                    \'value\' => $category,
                    \'compare\' => \'like\'
                )
            )
        );
        $user_query = new WP_User_Query($args);
 和我的分页链接:
<?php
              $total_user = $user_query->total_users;
              $total_pages=ceil($total_user/7);
                echo paginate_links(array(
                    \'base\' => get_pagenum_link(1) . \'%_%\',
                    \'format\' => \'?paged=%#%\',
                    \'current\' => $paged,
                    \'total\' => $total_pages,
                    \'prev_text\' => \'Previous\',
                    \'next_text\' => \'Next\',
                    \'type\'     => \'list\',
                ));
  ?>
 每当我尝试进行搜索时,都会得到如下url:
https://mywebsite.ca/directory/?search&category=Government#038;category=Government&paged=2
 
                SO网友:Stefan
                这是官方WordPress Codex中的示例https://codex.wordpress.org/Function_Reference/paginate_links#Example_With_a_Custom_Query
自定义查询示例:
<?php
//Protect against arbitrary paged values
$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
$args = array(
    \'posts_per_page\' => 5,
    \'category_name\' => \'gallery\',
    \'paged\' => $paged,
);
$the_query = new WP_Query( $args );
?>
<!-- the loop etc.. -->
 适应上述自定义查询的paginate\\u links参数示例:
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
    \'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
    \'format\' => \'?paged=%#%\',
    \'current\' => max( 1, get_query_var(\'paged\') ),
    \'total\' => $the_query->max_num_pages
) );
?>