I am facing very strange problem. Speaker is a custom post type and taxonomy. Target is showing all speakers which taxonomy is speaker as well.
When I am loading /speakers page, it is showing general blog posts. Also template is not same as archive-speaker.php. I have created another custom post type for testing which is working well. Only issue with speaker custom post type. It was working on another nginx server. After cloning the site to new nginx server, I see this problem.
My all configurations and testing:
register_post_type('speaker', array(
'labels' => array(
'name' => __('People', 'dxef'),
'singular_name' => __('People', 'dxef'),
'add_new' => __('Add New', 'dxef'),
'add_new_item' => __('Add New Person', 'dxef'),
'edit_item' => __('Edit Person', 'dxef'),
'new_item' => __('New Person', 'dxef'),
'all_items' => __('All People', 'dxef'),
'view_item' => __('View Person', 'dxef'),
'search_items' => __('Search People', 'dxef'),
'not_found' => __('No People found', 'dxef'),
'not_found_in_trash' => __('No People found in trash', 'dxef'),
'menu_name' => __('People', 'dxef')
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'speakers',
'with_front' => false
),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => 5,
'supports' => array(
'title',
'editor',
'thumbnail'
)
));
Loading taxonomy related customs_posts
add_action( 'pre_get_posts', 'speaker_archive' );
function speaker_archive( $query ) {
if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'speaker' ) ) {
$query->set( 'posts_per_page', '30' );
$taxquery = array(
array (
'taxonomy' => 'roles',
'field' => 'slug',
'terms' => 'speaker',
'operator' => 'IN'
)
);
$query->set( 'tax_query', $taxquery );
}
}
Above code is not being called any more. is_post_type_archive( 'speaker' )
returns false on /speakers
page. I have flushed rewrite rule by saving permalinks. But it does not solve my issue.
I am assuming before calling custom post type, general blog post is being called. But not sure how to detect why such happen and what is the actual solution.