[英]get_terms return errors
嗨,當我嘗試get_terms();
通過此代碼在主題選項中
$catalogs_terms = get_terms( 'catalogs' );
$mycatalogs = array( -1 => 'Select a catalog' );
if ( $catalogs_terms ) {
foreach ( $catalogs_terms as $catalog_term ) {
$mycatalogs[$catalog_term->term_id] = $catalog_term->name;
}
}
返回空,但是此代碼在頁面等中的每個位置都工作正常。當我嘗試print_r( $catalogs_terms )
輸出時,我遇到錯誤
Array ( [errors] => Array ( [invalid_taxonomy] => Array ( [0] => Invalid Taxonomy ) ) [error_data] => Array ( ) )
我不明白我在哪里錯? 我的注冊分類法職能
add_action( 'init', 'my_taxonomies', 0 );
function my_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Catalogs', 'taxonomy general name' ),
'singular_name' => _x( 'Catalog', 'taxonomy singular name' ),
'search_items' => __( 'Search Catalogs', 'mytextdomain' ),
'all_items' => __( 'All Catalogs', 'mytextdomain' ),
'parent_item' => __( 'Parent Catalog', 'mytextdomain' ),
'parent_item_colon' => __( 'Parent Catalog:', 'mytextdomain' ),
'edit_item' => __( 'Edit Catalog', 'mytextdomain' ),
'update_item' => __( 'Update Catalog', 'mytextdomain' ),
'add_new_item' => __( 'Add New Catalog', 'mytextdomain' ),
'new_item_name' => __( 'New Catalog Name', 'mytextdomain' ),
'menu_name' => __( 'Catalogs', 'mytextdomain' ),
);
// register catalogs hierarchical (like categories)
register_taxonomy( 'catalogs',
array( 'news' ),
array( 'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'public' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'catalogs' )
)
);
}
這應該使您走上正確的道路...
$qt = 'SELECT * FROM '.$wpdb->terms.' AS t INNER JOIN '.$wpdb->term_taxonomy.' AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = "<-- your taxonomy -->" AND tt.count > 0 ORDER BY t.term_id DESC LIMIT 0 , 30';
$terms = $wpdb->get_results($qt, ARRAY_A);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.