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.

i'm not new to wordpress templating nor a master. So i've had a problem when i wanted to make a custom list showing all categories and posts under them with a custom taxonomy and post type, like:

—–Cat Level 1
——-SubCat Level 1
——-SubCat Level 1
———-Post Title – cust_field_1 – cust_field_2
—–Cat Level 1
——-SubCat Level 1
———-Post Title – cust_field_1 – cust_field_2
———-Post Title – cust_field_1 – cust_field_2
——-SubCat Level 1
—–Cat Level 1

I know how to show custom post types, custom fields, custom taxonomies and posts but i really couldn't figure out how to set up this hierarchical view. It simply turns out all posts from all cats to all subcategories...

Thanks for all help...

my taxonomy name is 'egitimkat' and custom post-type is 'egitim'

and the code i use is

    <?php
/*
Template Name: Karabatakx
*/

get_header(); ?>

<?php
//get all categories then display all posts in each term
$taxonomy = 'egitimkat';
$param_type = 'egitimkat__in';
$term_args=array(
  'orderby' => 'name',
  'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
  foreach( $terms as $term ) {
    $args=array(
      "$param_type" => array($term->term_id),
      'post_type' => 'egitim',
      'post_status' => 'publish',
      'showposts' => 100
      );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {  ?>
      <div >
        <h3><?php echo $term->name;?></h3>
        <ul>
        <?php
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?> <?php print_custom_field('egitim_suresi'); ?>  <?php print_custom_field('egitim_bedeli'); ?></a></li>
       <?php
      endwhile;
      ?>
      </ul>
      </div>
 <?php
    }
  }
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
share|improve this question
add comment

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.