WP_Query arguments to fetch custom post type posts which are in certain category?

If you want your main query to take in account your custom post type, you can do as shown below :

function add_custom_post_type_to_query( $query ) {
    if ( $query->is_archive() && $query->is_main_query() ) {
        $query->set( 'post_type', array('post', 'my_custom_post_type') );
    }
}
add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );

You can place the above code in your theme’s functions.php or in a plugin.

In order to get the current taxonomy term id (here the taxonomy is the default “category” taxonomy), you can use the following line of code :

get_queried_object()->term_id;

(taken from here)

Since you are talking about custom post type, you’ll probably use custom taxonomy one day as well. To properly include some taxonomy filtering in a WP_Query, you can refer to this link

Here is a sample WP_Query with the category taxonomy :

$args = array(
    'post_type' => 'my_custom_post_type', // or multiples : array('my_custom_post_type','post')
    'tax_query' = array(
        array(
            'taxonomy' => 'category',
            'field'    => 'term_id',
            'terms'    => get_queried_object()->term_id,
        )
    )
);

But you’ll probably never want to do a WP_Query with a tax_query on your current taxonomy term since it does it automatically (after you added the custom post type in the main query post types)

tech