Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m wondering the same thing. We have a URL structure like this…

    https://mydomain.com/some-category/?subject=Some+Subject

    I’m trying to get pagination properly working. I urlencode() the space and get the +, but it doesn’t matter if I use a space or a + …Wordpress always tries to do this…

    https://mydomain.com/some-category/page/2/?subject=SomeSubject

    …instead of this…

    https://mydomain.com/some-category/page/2/?subject=Some+Subject

    WordPress is removing the space/+ for some reason. We haven’t figured out why just yet. Any help is greatly appreciated.

    The problem is caused by the canonical redirect checked on using a theme. If you place
    remove_action('template_redirect','redirect_canonical');
    in the functions.php file belonging to your template, the problem is fixed.

    If you want more information, see
    this related issue.

    Is there another fix. Cause remove_action(‘template_redirect’,’redirect_canonical’); just breaks everything.

    <?php
    global $wp_query, $wp_rewrite;
    $wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
    
    $pagination = array(
    	'base' => @add_query_arg('paged','%#%'),
    	'format' => '',
    	'total' => $wp_query->max_num_pages,
    	'current' => $current,
    	'show_all' => true,
    	'type' => 'plain'
    	);
    
    if( $wp_rewrite->using_permalinks() )
    	$pagination['base'] = get_bloginfo('url') . '/page/%#%/';
    
    $cq = $_GET['s'];
    	$sq = str_replace(" ", "+", $cq);
    
    if( !empty($wp_query->query_vars['s']) )
    	$pagination['add_args'] = array( 's' => $sq);
    
    echo paginate_links( $pagination );
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pagination removing space in query’ is closed to new replies.