Hello Jacob,
thanks for your reply. The Portfolio menu comes through a wordpress theme I bought.
Anyway, it does not matter this way because I have just tried on a fresh WP installation and got the same issue.
Just for your information, I installed a fresh copy of WP v4.7, I then added this snippet code to the functions.php file:
// Register custom post type "Gallery"
add_action('init', 'custom_post_type_callback');
function custom_post_type_callback(){
$args = array (
'public' => true,
'label' => 'Gallery',
'has_archive' => true,
'rewrite' => array('slug' => 'gallery'),
'supports' => array(
'title', 'editor', 'author', 'thumbnail', 'comments', 'revision'),
);
register_post_type('gallery', $args);
}
// Add an existing taxonomies to custom post type "Gallery"
add_action('init', 'add_taxonomies_gallery_callback');
function add_taxonomies_gallery_callback(){
register_taxonomy_for_object_type('post_tag', 'gallery');
register_taxonomy_for_object_type('category', 'gallery');
}
// Output Gallery posts in the archive page
add_filter ('pre_get_posts', 'add_gallery_posts_query_callback');
function add_gallery_posts_query_callback($query){
if ( is_archive() && $query->is_main_query() ) {
$query->set('post_type', array (
'post',
'gallery')
);
}
}
Maybe something wrong with the above snippet? I am not an expert, I must say, just followed one of many articles there are on the net about this task.
This is the screenshot of Posts menu page:
https://drive.google.com/open?id=0B-DXE7ThxZ20MWFaSFlBU3lwMXM
This is the screenshot of Gallery menu page:
https://drive.google.com/open?id=0B-DXE7ThxZ20UGdibW5HQkZDaEE
As you can see, in the latter there are 4 posts: two in red are the standard blog posts (as seen in the previous image), two in blue are the custom type posts called “Gallery”. Note also that under the page title is reported the current view should have only 2 published posts, but the query output 4 items.
I guess something is wrong in the function add_gallery_posts_query_callback I wrote above.
Thanks if you may help me.
Bye.
Riccardo