Wordpress是否在帖子页面中显示自定义帖子类型特定类别?
我是新手。我已经手动创建了一个自定义的post类型,如下所示的代码。我无法在自定义帖子类型中获取帖子表单特定类别(徽标、网站)。帮我解决这个问题Wordpress是否在帖子页面中显示自定义帖子类型特定类别?,wordpress,custom-post-type,Wordpress,Custom Post Type,我是新手。我已经手动创建了一个自定义的post类型,如下所示的代码。我无法在自定义帖子类型中获取帖子表单特定类别(徽标、网站)。帮我解决这个问题 function my_custom_taxonomies(){ $lables = array( 'name' => 'Type', 'singular_name' => 'my_custom_taxonomiesType', 'all_items' => 'All Type
function my_custom_taxonomies(){
$lables = array(
'name' => 'Type',
'singular_name' => 'my_custom_taxonomiesType',
'all_items' => 'All Types',
'add_new_item' => 'Add Type',
'edit_item' => 'Edit Type',
'search_item' => 'Search Type',
'parent_item' => 'Parent Type',
'parent_item_colon' => 'Parent Type',
'update_item' => 'Update Type',
'new_item_name' => 'New Type Name',
'menu_name' => 'Type'
);
$args = array(
'labels' => $lables,
'query_var' => ture,
'rewrite' => array('slug' => 'type'),
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
);
register_taxonomy('type', array('portfolio'), $args);
}
add_action('init','my_custom_taxonomies');
我正在尝试此代码,但无法使其正常工作
$args = array( 'post_type' => 'portfolio', 'category_name' => 'logo', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<ul>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
</ul>
<?php echo '<div class="entry-content">';
//the_content();
echo '</div>';
endwhile;?>
$args=array('post\u type'=>'公文包','category\u name'=>'徽标','posts\u per\u page'=>10);
$loop=新的WP_查询($args);
而($loop->have_posts()):$loop->the_post();?>
只要在注册分类法后使用它即可。您可以参考WP_查询
你能确认你的类别名称是否为“logo”吗?这是特定类别的url。你能确认它吗?你能通过删除
“Category\u name”=>“logo”
来运行WP\u Query()
,并检查你是否首先得到结果吗?如果我删除了“Category\u name”=>“logo”,它会显示所有帖子。这是我在自定义帖子类型中创建的。欢迎@Gagau:-)。请把这个也投上一票,以便对其他人有用
$query = new WP_Query( array(
'post_type' => 'portfolio',
'tax_query' => array(
array (
'taxonomy' => 'type',
'field' => 'slug',
'terms' => 'logo',
)
),
) );