wordpress - Wordpress 在帖子页面中显示自定义帖子类型特定类别?
问题描述
我是新开发的。我手动创建了一个自定义帖子类型,如下面的代码所示。我无法在自定义帖子类型中获取帖子表单特定类别(徽标、网站)。帮我解决这个问题。
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;?>
解决方案
只需使用它,因为您已经注册了分类法。您可以在此处参考 WP_Query
$query = new WP_Query( array(
'post_type' => 'portfolio',
'tax_query' => array(
array (
'taxonomy' => 'type',
'field' => 'slug',
'terms' => 'logo',
)
),
) );
推荐阅读
- python - 从已定义的类中使用 Django 生成 ZipFile
- azure - Azure AD Graph API 邀请终结点
- html - 为什么使用 flex justify-content: space-between 时悬停会有间隙?
- c# - 从数据库中获取 XML 并合并它们
- javascript - 共享全局变量/存储在 Vue JS 中不起作用
- firebase - 发生错误时如何中止 Firestore 事务
- ios - 文本字段隐藏了聊天的最后一条消息 - Swift
- git - “这里的 Git bash”和“这里的 Git GUI”在 Windows 10 上不起作用
- android - vivo 和 oppo 设备没有收到推送通知
- shell - 使用 bash:如何根据输入文件行内容拆分文件?