Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Lets say I am inside custom taxonomy subtaxonomy. Viewing either archive.php or single.php page.

I want to display there only subcategories what are same level as the one what I am looking.

Now it will show me also other subcategories what are listed under another top level category.

My current code is:

<?php



$args=array(
'post_type'                => 'koogid',
'child_of'                 => 0,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  => '',
'number'                   => '',
'taxonomy'                 => 'custom_cat',
'pad_counts'               => false
);

$categories=get_categories($args);





foreach ( $categories as $category ) {

if ( $category->parent > 0 ) {
continue;
}

 echo '<h1 style="font-weight:bold">' . $category->name . '</h1>';

$querystr = "SELECT $wpdb->posts.*
              FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->terms
              WHERE term_id = (" . $category->cat_ID . ")
              AND term_taxonomy_id = (" . $category->term_taxonomy_id . ")
              AND ID = object_id
              AND post_type = 'biblioteka'
              AND post_status = 'publish'
              ORDER BY post_date DESC";


$categories2 = get_terms('custom_cat',array('parent' => $category->term_id , 'hide_empty'=> '0' ));




foreach ( $categories2 as $category ) {

// echo '<h5>' . $category->name  .'</h5>';

echo '<li><a href="' . esc_attr(get_term_link($category)) . '" title="' .  $category->name  . '" ' . '>' . $category->name.'</a></li>';

}
}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.