Skip to main content
<?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
?>
<?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'  => $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
?>
<?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
                        '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 IMPORTANT to reset the $post global to main query
            } // endif $posts_array
        } // endforeach $wsubcats
    } // endforeach $wcatTerms
} // endif check for valid array of terms
?>
added 1 character in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
<?php
$taxonomy = 'menu-items'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'  => $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
?>
<?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'  => $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
?>
<?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'  => $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
?>
added 3 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

Sifting through your code, there a plentare plenty errors. I have corrected all that errors in your code and have commented on them inside the code, so make sure to check my comments. Where I have stated to remove, remove that specific line of code as it is not necessary. Also, I do not know if you really need empty terms, so I have left that and just build in protection to avoid bugs and errors if there are actually empty terms

Sifting through your code, there a plent errors. I have corrected all that errors in your code and have commented on them inside the code, so make sure to check my comments. Where I have stated to remove, remove that specific line of code as it is not necessary. Also, I do not know if you really need empty terms, so I have left that and just build in protection to avoid bugs and errors if there are actually empty terms

Sifting through your code, there are plenty errors. I have corrected all that errors in your code and have commented on them inside the code, so make sure to check my comments. Where I have stated to remove, remove that specific line of code as it is not necessary. Also, I do not know if you really need empty terms, so I have left that and just build in protection to avoid bugs and errors if there are actually empty terms

added 4038 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
Loading
added 1 character in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
Loading
added 835 characters in body
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
Loading
Post Undeleted by Pieter Goosen
Post Deleted by Pieter Goosen
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209
Loading