0

I have initiated couple of custom taxonomies, using the following code

function sources_init() {

register_taxonomy('sources','post',array(
        'hierarchical'          => true,
        'labels' => array (
            'name'              => _x( 'News Sources', 'taxonomy general name' ),
            'singular_name'     => _x( 'News Source', 'taxonomy singular name'),
            'search_items'      => __( 'Search News Sources' ),
            'parent_item'       => __( 'Parent Topic' ),
            'parent_item_colon' => __( 'Parent Topic:' ),
            'edit_item'         => __( 'Edit Sources' ),
            'update_item'       => __( 'Update Sources' ),
            'add_new_item'      => __( 'Add a News source' ),
            'new_item_name'     => __( 'New News Source' ),
            'menu_name'         => __( 'News Sources' ),

        ),
          $args = array( 
            'labels'                => $lables,
            'public'                => true,
            'query_var'             => true,
            'show_ui'               => true,
            'update_count_callback' => 'update_post_term_count',
            'show_admin_column'     => true,
            'show_in_nav_menus'     => true,
            'rewrite' => array( 
                    'slug'          => 'sources'
                     )
            )       
));
}
add_action( 'init', 'sources_init', 0 );

this is an example of code I am using, and there is no problem for now, specially when I call a custom post type in its template archive-slug-name.php. But the problem appears in two places:

1- wp_list_categories()

<?php $taxonomy = 'sources'; 
              $title = '';
              $args = array(
                    'taxonomy'     => $taxonomy,
                    'title_li'     => $title,
                    'hierarchical' => $hierarchical,
              );
        ?>
        <ul>
            <?php wp_list_categories('title_li=&include=45,51'); ?>
        </ul>

2- using tax_query tag to show cpt in its each category page:

$loop = new WP_Query(array(
'post_type' => 'documents',
'posts_per_page' => 20,
'tax_query' => array(array(
    'taxonomy' => 'sources',
    'terms' => get_queried_object_id(),
)),
));

So is there any problem with the way I initiated the custom Taxonomy? Or the problem with the way I call the categories?

Edit screenshot for taxonomy slug and cat iD

  • In both cases you are using term IDs. For starters does wp_list_categories() work in very general case, without IDs? – Rarst Jan 4 '15 at 16:38
  • yes with no problem. – Kareem Jan 4 '15 at 16:56
  • Then are you sure your IDs are correct and belong to valid terms? – Rarst Jan 4 '15 at 17:08
  • yes, that would be a problem for the first case, but the second doesn't require a term ID. Am I right? – Kareem Jan 4 '15 at 17:19
  • You are very clearly using one in second case too?.. 'terms' => get_queried_object_id() Value might not be what you assume. – Rarst Jan 4 '15 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.