I will query all posts of a custom post type if the visitor is in the assigned custom taxonomy. I can use an array of all my custom post types in the argument list, but I want to do it dynamicly with the informations of the category the visitior is in. Is there a way to get the custom post type name from the current taxonomy?
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
if ( ! $paged ) {
$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
}
$posts_per_page = get_option( 'posts_per_page' );
// Get the queried object and sanitize it
$current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
// Get the slug
$slug_taxonomy = @$current_page->taxonomy;
// Check if I'm in a category
if ( isset( $slug_taxonomy ) && ! is_null( $slug_taxonomy ) && ! empty( $slug_taxonomy ) ) {
$query = new WP_Query( array(
'posts_per_page' => $posts_per_page,
'post_type' => 'i_dont_know', // How can I get the custom post type?
'paged' => $paged,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => $current_page->taxonomy,
'field' => 'term_id',
'terms' => $current_page->term_id,
)
)
)
);
}