Ok, so I sort of isolated the issue by setting the if statement for each post type individually.
For the posts it works as it should. While on the post page I click on a category and it takes me to the category.php template displaying the posts with that category.
For the portfolio posts I use the code below and it takes me to the right template, but it displays ALL of the portfolio posts, not just the ones related to the selected category.
This is the code I use for the portfolio posts:
$args = array('post_type' => 'portfolio');
$portfolio = new WP_Query( $args );
if ( $portfolio->have_posts() ) : while ( $portfolio->have_posts() ) : $portfolio->the_post();
What would be reason the selected category doesn’t apply to these posts? Also, how do I construct the if statement to load either the regular posts or portfolio posts?
Here is the code initallizing the custom post type:
function custom_post_type() {
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project',
'all_items' => 'All Projects',
'new_item' => 'New Project',
'view_item' => 'View Portfolio',
'search_item' => 'Search Portfolio',
'not_found' => 'No projects found',
'not_found_in_trash' => 'No products found in trash',
'parent_item_colon' => 'Parent Item'
);
$args = array(
'rewrite' => array('slug' => 'portfolio'),
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'thumbnail',
'editor',
'excerpt',
'revisions'
),
'taxonomies' => array( 'category', 'post_tag' ),
'menu_position' => 4, // position where this is located in admin panel
'exclude_from_search' => false,
'menu-icon' => 'dashicons-clipboard' // wordpress icons
);
register_post_type('portfolio', $args);
}
add_action('init', 'custom_post_type');