<?php
$taxonomy = 'menu-items'; // Do not use hypens in taxonomy names, only use underscores
$term_args = array(
'hide_empty' => 0, // Why do you need empty terms?
'orderby' => 'ASC',
'parent' => 0
);
$wcatTerms = get_terms(
$taxonomy, // Taxonomy name
$term_args // Array of arguments to get terms by
);
// To avoid bugs and errors, run this only if we have a valid array of terms
if ( !empty( $wcatTerms ) // Check that we do not have an empty array
&& !is_wp_error( $wcatTerms ) // Check that we do not have a WP_Error object returned
) {
// If our conditional check passed, then only run the following code
foreach($wcatTerms as $wcatTerm) { // Do not use : as it is hard to debug and to read, use old style curlies
//echo $wcatTerm->name;
$wsubargs = array(
//'hierarchical'=>1, // This is default, not needed and can be removed
//'show_option_none'=>'', // Invalid parameter, where do you get this from, to remove
'hide_empty'=> 0, // Why do you need empty terms?
'parent'=>$wcatTerm->term_id,
);
//$wsubcats = get_categories($wsubargs); // Why use get_categories, get_categories uses get_terms, to remove
$wsubcats = get_terms(
$taxonomy, // We have set this earlier
$wsubargs
);
foreach ( $wsubcats as $wsc ) { // Again, do not use : as it is hard to debug
?><h2><?php //echo $wsc->name; ?></h2>
<?php $childcat = $wsc->name; ?>
<h2><?php echo $childcat; ?></h2>
<?php
//$posts = get_posts(array( // Do not mess with $posts global, rather use $posts_array, to remove
$args = array(
'post_type' => 'menu', // Really bad name, reserved name in Wordpress
'orderby' => 'name',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => $taxonomy, // We have defined this already right at the start
'term''terms => $wsc->term_id,
'include_children' => false,
)
),
'nopaging' => true,
);
$posts_array = get_posts( $args );
// You are missing the loop here, that is why you are getting the same stuff over and over again
if ( $posts_array ) { // Only run this if we actually have posts, if we do not have posts, we will have bugs and errors
foreach ( $posts_array as $post ) { // You were missing this
setup_postdata( $post ); // VERY VERY IMPORTANT, without this, the template tags like the_content will not work
?>
<div class="menu-title"><?php the_title(); ?></div>
<div class="menu-title"><?php the_content(); ?></div>
<?php } // endforeach $posts_array
wp_reset_postdata(); // VERY VERY IMPORTANT to reset the $post global to main query
} // endif $posts_array
} // endforeach $wsubcats
} // endforeach $wcatTerms
} // endif check for valid array of terms
?>