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:
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:
However... when you try to view the second page of pagination, here:
https://gateleyplc.com/corporate-deals/page/2/
it redirects to:
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' );
?>
https://gateleyplc.com/corporate-deals
as a page with a shortcode, rather than use the custom post type archive page that WordPress generates?/corporate-deals/page/2/
, WordPress is querying for the 2nd page of a singularcorporate-deals
post with the slugpage
. If you used the built-in archive instead of a page, this issue would disappear. You'll need to add your own rewrite rules to override the ones generated for your post type.