基于自定义帖子类型的自定义分类法显示帖子时出现问题。我可以将所有帖子显示在自定义帖子类型中,但不仅仅是分类法。
以下是我如何注册帖子类型
function reg_forms() {
$labels = array(
\'name\' => _x( \'Forms\', \'post type general name\' ),
\'singular_name\' => _x( \'Form\', \'post type singular name\' ),
\'add_new\' => _x( \'Add New\', \'Form\' ),
\'add_new_item\' => __( \'Add New Form\' ),
\'edit_item\' => __( \'Edit Form\' ),
\'new_item\' => __( \'New Form\' ),
\'all_items\' => __( \'All Forms\' ),
\'view_item\' => __( \'View Forms\' ),
\'search_items\' => __( \'Search Forms\' ),
\'not_found\' => __( \'No Forms found\' ),
\'not_found_in_trash\' => __( \'No Forms found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Forms\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Forms for download\',
\'public\' => true,
\'menu_position\' => 5,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\', \'comments\' ),
\'has_archive\' => true,
);
register_post_type( \'forms\', $args );
}
add_action( \'init\', \'reg_forms\' );
function my_taxonomies_product() {
$labels = array(
\'name\' => _x( \'Form Categories\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Form Category\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Form Categories\' ),
\'all_items\' => __( \'All Form Categories\' ),
\'parent_item\' => __( \'Parent Form Category\' ),
\'parent_item_colon\' => __( \'Parent Form Category:\' ),
\'edit_item\' => __( \'Edit Form Category\' ),
\'update_item\' => __( \'Update Form Category\' ),
\'add_new_item\' => __( \'Add New Form Category\' ),
\'new_item_name\' => __( \'New Form Category\' ),
\'menu_name\' => __( \'Form Categories\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
);
register_taxonomy( \'form_category\', \'forms\', $args );
}
add_action( \'init\', \'my_taxonomies_product\', 0 );
这里是查询。
$the_query = new WP_Query($args = array(
\'post_type\' => \'forms\',
\'custom_cat\' => \'form_category\',
) );
// The Loop
if ( $the_query->have_posts() )
{
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo "<div>";
echo get_the_title();
echo "</div>";
;?>
<?php
}
}
else {
wp_reset_postdata();
}