Im trying to output category with its post on a single page, but for some reason the post from all category are repeating in each category, what am i doing wrong here Here the code:

        #Template Name: food

        $taxonomy = 'category';
        $param_type = 'category__in';

        $term_args = array(
                'orderby' => 'name',
                'order' => 'ASC',
                'exclude' => 1
        $terms = get_terms($taxonomy, $term_args);

<div class="row">
        <?php if($terms) : ?>

                <?php $counter = 0; foreach($terms as $term) : $counter++; ?>

                                $args = array(
                                        '$param_type' => array($term->term_id),
                                        'post_type' => 'food',
                                        'post_status' => 'publish',
                                        'posts_per_page' => -1

                                $my_query = null;
                                $my_query =  new Wp_Query($args);

                        <?php if($my_query->have_posts()) : ?>

                                        <?php if($counter == 2): ?>
                                                <ul class="menu-list sixcol last">
                                        <?php $counter = 0; else: ?>
                                                <ul class="menu-list sixcol">
                                        <?php endif; ?>

                                                <h3><?php echo $term->name; ?></h3>
                                                        while($my_query->have_posts()): $my_query->the_post();
                                                        $post_meta_data = get_post_custom($post->ID);
                                                        $price = $post_meta_data['fangshsu_price'][0];

                                                                <strong><?php the_title(); ?></strong>
                                                                <i><?php if($price) {echo '&pound;' . $price;} ?></i>
                                                                <?php the_content();?>

                                                <?php wp_reset_query(); endwhile; ?>

                        <?php endif; ?>

                <?php endforeach; ?>

        <?php endif; ?>
<?php get_footer(); ?>
  • 4
    A question should never rely on an external page. Please add the code to your question and add debug information.
    – fuxia
    Commented Apr 30, 2013 at 22:56
  • i 2nd that (but isnt it nice the code have line numbers? makes life a lot easier - should be on the to do list for sure.
    – Sagive
    Commented Apr 30, 2013 at 23:32
  • 2
    @SagiveSEO : post that on WordPress Development Meta if the point hasn't already been raised
    – s_ha_dum
    Commented Apr 30, 2013 at 23:37

1 Answer 1


You are calling a weird parameter in line 24 which i dont understand... did you copy paste this function from elsewhere?

change line 24 from:

'$param_type' => array($term->term_id),

To this:

'cat' => array($term->term_id),

Good luck and dont forget to read @toscho comment for future questions.

  • He has set $param_type earlier in the code (line 8). But you're right - wrapping it in single quotes will cause that param to fail.
    – vancoder
    Commented Apr 30, 2013 at 23:41
  • thanks mate... searched for that (should have done it with chrome which simply highlights..) thanks for the heads up.
    – Sagive
    Commented May 1, 2013 at 0:18
  • @vencoder your spot on the single quote was the culprit i removed it everything work good now. any advice on how to tidy up this code i feel it look messy
    – John Doe
    Commented May 1, 2013 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.