0

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:

<?php
        #Template Name: food
        get_header();
 ?>

<?php
        $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++; ?>

                        <?php
                                $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>
                                                <?php
                                                        while($my_query->have_posts()): $my_query->the_post();
                                                        $post_meta_data = get_post_custom($post->ID);
                                                        $price = $post_meta_data['fangshsu_price'][0];
                                                 ?>

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

                                                <?php wp_reset_query(); endwhile; ?>
                                        </ul>

                        <?php endif; ?>

                <?php endforeach; ?>

        <?php endif; ?>
</div>
<?php get_footer(); ?>
3
  • 4
    A question should never rely on an external page. Please add the code to your question and add debug information.
    – fuxia
    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
    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
    Apr 30, 2013 at 23:37

1 Answer 1

1

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

anyhow...
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.

3
  • 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
    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
    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
    May 1, 2013 at 0:27

Your Answer

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

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