Setting up archive for a specific category

I have categories that are assigned to various post types, including the standard “Posts” post type. I want to create an archive layout that it loops through and shows ALL posts (of all post types - let’s say post types “Posts”, “A”, and “B”) that have the category “latest-news” assigned to them.
Does this work with a standard archive page, or do I need to set up a custom looper for that?
I get it to work with a looper provider on the archive page, but then the paginations doesn’t work anymore.
Do I need to set up a query in functions.php to achieve that?
What is then the proper assignment in the archive layout setting?

Hello @striata,

Thank you for the inquiry.

You may need to create a custom looper that retrieves items in the same category from multiple post types.

Example:

add_filter('cs_looper_custom_archive_post_type', function ($result, $args) {
    $query_args = array(
        'post_type'      => array('post', 'journal'),
        'tax_query'      => array(
            array(
                'taxonomy' => 'category',
                'terms'    => $args['term_id'],
                'field'    => 'id',
            ),
        ),
        'posts_per_page' => -1,
        'post_status'    => 'publish',
    );

    $posts = get_posts($query_args);

    return $posts;
}, 10, 2); 

This should retrieve items from the post types array(‘post’, ‘journal’). In the Looper Provider > Custom, set the hook value to “archive_post_type”, then include the following parameters:

{
  "term_id": "{{dc:term:id}}"
}

Set the Assignment > Conditions of the archive layout to the post types where you need to apply the template or layout.

Let us know if this works for you.

Best regards,
Ismael

Thank you, Ismael. However, this means that I have to explicitly specify a looper provider on the archive layout? Will pagination then still work?

Hey @striata,

Yes, you are right! Using Looper Provider inside the archive layout, the pagination will not work. With that said, you just need to set the post category in the condition and use the and

Hope that helps.

Thank you, Marc, but that doesn’t do what I would like to achieve. First, I do not want two different Post Categories, but the same Category of different post types. For example: "Post Category" is "Cool" and "Publication Category" is "Cool".
However, It would then not show all Coolposts of BOTH post types on a single page, would it?

Hello @striata,

Sorry for the confusion. Be advise that a category archive will only display post items by default. To display all the post types in a category archive, you will have to modify WordPress query variables. For example;

function include_custom_post_types_in_category_archive($query) {
    if ($query->is_category() && $query->is_main_query()) {
        $query->set('post_type', array('post', 'your_custom_post_type')); // Add your custom post types here
    }
}
add_action('pre_get_posts', 'include_custom_post_types_in_category_archive');

The feature that you wanted is something NOT the default WordPress archive loop does. Be advised that custom coding is beyond the scope of our support under our Support Policy. If you are unfamiliar with code and resolving potential conflicts, you may select our One service for further assistance.

The code above is just an example. You may need to modify as it may not work for you out of the box.

Cheers.

Thank you!

You are most welcome.