简体   繁体   中英

Wordpress pagination on Custom Post Type not working

I am having an issue with my custom post type and pagination. My custom post type is "vacancies".

I have created a custom archive template "archive-vacancies.php"

The page URL is "mydomain.com/vacancies"

Here is my code:

    global $wp_query, $paged;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array_merge( $wp_query->query_vars, array( 'posts_per_page' => 3, 'paged'=>$paged ) );

    query_posts( $args );

            if ( have_posts() ) :

                while ( have_posts() ) : the_post();

                  //display code goes here

                endwhile;

            else :

                get_template_part( 'includes/no-results', 'index' );

            endif;

            ?>

            <?php wp_pagenavi(); ?>

Everything works when I am on the main page ie mydomain.com/vacancies and the pagination shows the correct links but when I click on page 2 of the pagination links it goes to mydomain.com/vacancies/page/2 and the template defaults to archive.php and I get a "No Results" message.

Any help is much appreciated.

If anyone comes across this issue, you can add this to your functions.php code

add_filter('redirect_canonical','pif_disable_redirect_canonical');

function pif_disable_redirect_canonical($redirect_url) {
    if (is_singular()) $redirect_url = false;
return $redirect_url;
}

remember to change is_singular () to is_tax / is_home or the type of page on which the loop is being made

https://wordpress.stackexchange.com/questions/129486/using-paged-redirects-page-2-to-page-1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM