0
votes

I got custom post types and categories made for them. All I want to do is to list all the custom categories with list of all posts that belongs to this category (with title and excerpt). None of the solutions I found works. I can display custom categories but can't list posts that belong to these categories. Here's my code

<?php
    $show_count = 0; 
    $pad_counts = 0; 
    $hierarchical = 1; 
    $taxonomy = 'timeline_category';
    $title = '';
    $description = true;

    $args = array(
    'show_count' => $show_count,
    'pad_counts' => $pad_counts,
    'hierarchical' => $hierarchical,
    'taxonomy' => $taxonomy,
    'use_desc_for_title' => $description,
    'title_li' => $title
     );

   $categories=get_categories($args);
   foreach($categories as $category) { 
  echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
echo '<p> Description:'. $category->description . '</p>';
echo '<p> Post Count: '. $category->count . '</p>'; 

    //display posts
$cat_new = $category->term_id;
$post_args = array( 'numberposts' => 5, 'category' => $cat_new, 'caller_get_posts' => 0 );


$myposts = get_posts( $post_args );
    foreach( $myposts as $post ) :  setup_postdata($post); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>

   <?php endforeach; }    ?>

The code above shows even that there is 1 post in this category (Post Count) so the problem is somwhere in foreach agrument for posts.

Any ideas?

Thanks

1

1 Answers

0
votes

I'm not too familiar with endforeach;, but after a quick Google search, it looks like you have a syntax error.

<?php foreach($foo as $bar):
    // Stuff
endforeach; // No trailing "}" ?>

Or

<?php foreach($foo as $bar){
    // Stuff
} ?>