如果访问者在指定的自定义分类中,我将查询自定义帖子类型的所有帖子。我可以在参数列表中使用所有自定义帖子类型的数组,但我想用visitior所属类别的信息动态地执行此操作。有没有办法从当前的分类法中获取自定义帖子类型名称?
$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,
)
)
)
);
}