Custom Post Type canonical link / pagination redirecting to root

I have inherited an existing site and have recently been asked to make some changes.

They have ‘renamed’ the default post as ‘latest-news’ using this ‘my_new_default_post_type’:

<?php

add_action( 'init', 'my_new_default_post_type', 1 );

    function my_new_default_post_type() {

      register_post_type( 'post', array(
          'labels' => array(
              'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
          ),
          'public'  => true,
          '_builtin' => false,
          '_edit_link' => 'post.php?post=%d',
          'capability_type' => 'post',
          'map_meta_cap' => true,
          'hierarchical' => false,
          'rewrite' => array('slug' => 'latest-news','with_front' => false),
          'query_var' => true,
          'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
      ) );

  }

?>

These can be seen being listed on a standard page here:

https://gateleyplc.com/news-events/latest-news/

with the second page of pagination here:

https://gateleyplc.com/news-events/latest-news/page/2/

Clicking into a post loads it here:

https://gateleyplc.com/latest-news/gateley-plc-celebrates-sixth-anniversary-in-yorkshire-with-the-appointment-of-six-new-solicitors/

I have added some new custom post types, one example of which is ‘corparate-deals’. The code to add this custom post type is:

<?php

    add_action('init', 'corporate_deals_register');

    function corporate_deals_register() {

     $labels = array(
        'name' => _x('Corporate Deals', 'post type general name'),
        'singular_name' => _x('Corporate Deals', 'post type singular     name'),
        'add_new_item' => __('Add New Briefing'),
        'edit_item' => __('Edit briefing'),
        'new_item' => __('New briefing'),
        'view_item' => __('View briefing'),
        'search_items' => __('Search Corporate Deals'),
        'not_found' =>  __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
      'labels' => $labels,
      'public' => true,
      'has_archive' => false,
      'show_ui' => true,
      'capability_type' => 'post',
      'taxonomies'  => array( 'category' ),
      'hierarchical' => false,
      'publicly_queriable' => false,
      'show_ui' => true,
      'show_in_nav_menus'  => false,
      'exclude_from_search' => false,
      'menu_icon' => 'dashicons-welcome-add-page',  // Icon Path
      'menu_position' => 5,
      'show_in_menu'  =>    'blogs_menu',
      'query_var' => true,
      'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions' ),
    );

    register_post_type( 'corporate-deals' , $args );
  }

?>

You can see these listed here:

https://gateleyplc.com/corporate-deals

and clicking into one here:

https://gateleyplc.com/corporate-deals/gateley-corporate-team-advises-on-firms-acquisition-of-kiddy-partners/

However… when you try to view the second page of pagination, here:

https://gateleyplc.com/corporate-deals/page/2/

it redirects to:

https://gateleyplc.com

I have searched high and low for any redirects or rewrite rules but cannot find any.

One thing I did notice is that if I add:

'rewrite' => array('slug' => 'latest-news','with_front' => false),

to my custom post declaration (i.e. rewriting the ‘corporate-deals’ to ‘latest-news’) then the redirection doesn’t occur.

Any help greatly appreciated. Thanks in advance.

Additionally

The code that builds the post listing is:

<?php // Corporate Deals

function paginatedcorporatedeals_func( $atts ) {

  extract( shortcode_atts( array(
    'pageid' => '{$pageid}',
    'title' => '{$title}',
    'showcontent' => '{$showcontent}',
    'newsurl' => '{$newsurl}',
    'postmeta' => '{$postmeta}'
  ), $atts ) );

  $output;

  global $post;

  $ws = 1;

  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

  $args = array(
    'post_type'=>'corporate-deals',
    //'order'=>'ASC',
    'posts_per_page' => 16,
    'paged' => $paged,
  );

  $slug = the_slug();

  query_posts($args);

  // global $wp_query;

  // $postcount = $wp_query->found_posts;

  $count=0;

  if(have_posts()) {

    $divider = 'yes';
    $featuredimg = 'date';
    $truncate = 250;

    while (have_posts()) : the_post();

      global $post;

      $thetitle = get_the_title($post->ID);

      require get_template_directory() . '/assets/inc/plugins/vc-intergration/modules/shortcode-templates/media-list.php';

      $output .="<hr>";

      $count++;

    endwhile;

    $output .=  "<div class='vc_row clearfix'><div class='white-bar'>".page_pagination()."</div></div>";

    wp_reset_query();
  }

  return $output;

}

add_shortcode( 'paginatedcorporatedeals', 'paginatedcorporatedeals_func' );

?>

$299 Affordable Web Design WordPress

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Custom Post Type canonical link / pagination redirecting to root

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.
Shopping Cart
There are no products in the cart!
Continue Shopping
0