I’m not sure why you are only getting 1 post returned. Your query args look correct, even if as I mentioned in the comment you should be using WP_Query
. Therefore, if I had to guess, I would say your looped html markup is off? And is maybe not printing the results correctly. I’ve modified your code to only have 1 get_categories()
and categories loop. I don’t know if it is more or less “readable” this way, but it seems to work for me.
$args = array(
'orderby' => 'name',
'parent' => 13
);
$categories = get_categories( $args );
$tabs="";
$panes="";
if( $categories ){
$tabs .= '<ul id="download-tab" class="nav nav-tabs resp-tabs-list">';
$panes .= '<div class="tab-content resp-tabs-container" id="download-content">';
$i=0;
foreach ( $categories as $category ) {
$i++;
$tabs .= '<li><a id="#'.$category->slug.'" href="https://wordpress.stackexchange.com/questions/158615/dtab".$i.'">' . $category->name . '</a></li>';
$post_args = array( 'category_name' => $category->slug,
'posts_per_page' => -1,
'order' => 'desc' );
$category_posts = new WP_Query( $post_args );
$panes .= '<div class="tab-pane" id="https://wordpress.stackexchange.com/questions/158615/dtab" .$i . '">';
if ( $category_posts->have_posts() ) :
$panes .= '<table class="table table-hover">
<tr>
<th>DATE</th>
<th>TITLE</th>
<th>SIZE</th>
<th></th>
</tr>';
while ( $category_posts->have_posts() ) : $category_posts->the_post();
$file_size = function_exists( 'rwmb_meta' ) ? rwmb_meta('file_size') : '';
$file_url = function_exists( 'rwmb_meta' ) ? rwmb_meta( 'file_url') : '';
$panes .= '<tr>
<td>'. get_the_time('d/m/Y') .'</td>
<td>'. get_the_title() .'</td>
<td>'. $file_size .'</td>
<td><a href="'. $file_url .'" class="button3 download_btn" target="_blank">DOWNLOAD</a></td>
</tr>';
endwhile;
$panes .= '</table>';
else:
$panes .= '<p>' . __( 'Sorry, no content found.' ) . '</p>';
endif;
$panes .= '</div><!--#dtab' .$i . '-->';
}
$panes .= '</div><!--#download-content-->';
$tabs .= '</ul><!--#download-tab-->';
}
// print it all out
echo $tabs;
echo $panes;