• Resolved top-node

    (@top-node)


    After reading everything that Google found and not having any success, here is my problem. It “seems” to be related to the “navigation not working” issues but none of the fixes actually fix it.

    This is the current code that I have (I’ll outline what is happening below):

    if ( get_query_var('paged') ) {
        $paged = get_query_var('paged');
    } elseif ( get_query_var('page') ) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    
    $lots_args = array(
    	'order'          => 'ASC',
    	'orderby'        => 'meta_value_num',
    	'meta_key'       => 'lot_number',
    	'posts_per_page' => 16,
    	'post_type'      => 'auction_lot',
    
    	'meta_query'     => array(
    		array( 'key' => 'lot_auction_id', 'value' => $auction_id )
    	),
    	'paged'          => $paged
    ); //$args
    
    $wp_query = new WP_Query( $lots_args );
    
    if ( $wp_query ) { // are there any lot items
    	while ( $wp_query->have_posts() ) {
            $wp_query->the_post();
            // display the posts
        }
    }
    
    wp_pagenavi( array( 'query' => $wp_query ) );

    When using the “simple” permalink, everything works, but when using the “Post name” permalink, WordPress is redirecting https://myurl.com/subpage/page/2/ to https://myurl.com/subpage/. Interestingly, https://myurl.com/subpage/2/ works.

    I found an issue related to WordPress 4.1 (I think) relating to this, but this was fixed in 4.2.
    Any ideas where to check what is going on and how to fix it?

    https://www.ads-software.com/plugins/wp-pagenavi/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter top-node

    (@top-node)

    I’ve found a fix for this on this page – https://core.trac.www.ads-software.com/ticket/15551

    Adding the code below to the functions.php file worked:

    <?php
    function fix_request_redirect( $request ) {
    
            if ( isset( $request->query_vars['post_type'] )
                 && 'custom_type' === $request->query_vars['post_type']
                 && true === $request->is_singular
                 && - 1 == $request->current_post
                 && true === $request->is_paged
            ) {
                    add_filter( 'redirect_canonical', '__return_false' );
            }
    
            return $request;
    }
    
    add_action( 'parse_query', 'fix_request_redirect' );

    Where you’ll have to update “custom_type” with the name of custom post type.

    OH… my god!!

    Thank you, thank you, thank you!!!

    I have been trying to fix this issue on a website I’m working on for over a month and I have tried just about everything. This piece of code, added to the ‘functions.php’ file, has fixed it and finally got pagination working with my Custom Post Type.

    Absolutely awesome and thanks for posting this

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘URL rewriting on custom post type’ is closed to new replies.