[英]Wordpress - How can I get_categories from additional custom post?
我的目標是從我在functions.php 中注冊的附加自定義帖子中獲取類別。 如何獲取它的類別並在我的頁面上回顯它? 到目前為止,這是我的代碼:來自頁面:
<?php
$args = array(
'post_type' => 'pdf',
'orderby' => 'slug',
'order' => 'ASC',
'parent' => 0,
'hide_empty' => false
);
$categories = get_categories($args);
foreach( $categories as $category ){
echo '<option><a class="ctg" href="'. get_category_link( $category->term_id ) .' ">' . $category->name . '</a></option>';
}
?>
來自函數。php
$args = array(
'label' => 'category',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_admin_column' => true,
'hierarchical' => true,
'query_var' => true
);
register_taxonomy('pdf_cat','pdf',$args);
wordpress 中自定義帖子類型的類別使用分類功能。 在這種情況下,您可以使用get_terms
來獲取“類別”。
例子
$categories = get_terms([
'taxonomy' => 'pdf_cat',
'hide_empty' => false,
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.