Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm outputting a list of categories with the posts inside the ul. This works fine on a normal pages but not on the single-product.php page. It breaks on the single-product.php page with the line have_posts. What is the problem?

  <?php  
  $post_type = $wp->query_vars["product"];
  $tax = 'product_category';
  $tax_terms = get_terms($tax,'hide_empty=0');

  if (is_array($tax_terms)) {
    foreach ($tax_terms  as $tax_term) {
      $args=array(
        'post_type' => $post_type,
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'caller_get_posts'=> 1
      );
      $my_query = new WP_Query($args);
      if ( $my_query->have_posts() ) {
        echo "<li><div>$tax_term->name</div>";
        echo "<ul>";
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php  $delta_article_number = get_post_meta( get_the_ID( ), 'delta_article_number', true );  echo $delta_article_number;  ?> <?php the_title(); ?></a></li>
          <?php
        endwhile;
        echo "</ul></li>";
      }

    }
  }
  wp_reset_postdata();  wp_reset_query();
  ?>
share|improve this question
    
turn on the debug, and check error message and share it so we can have more detail :) –  andresmijares25 Jan 24 '12 at 15:00

1 Answer 1

up vote 0 down vote accepted

A part of the problem was that "caller_get_posts" is deprecated, it is now "ignore_sticky_posts".

The main problem was this line "$post_type = $wp->query_vars["product"];", i removed this one and replaced the $post_type with 'product'.

This code works!

  <?php  
  $tax = 'product_category';
  $tax_terms = get_terms($tax,'hide_empty=0');

  if (is_array($tax_terms)) {
    foreach ($tax_terms  as $tax_term) {
      $args=array(
        'post_type' => 'product',
        "$tax" => $tax_term->slug,
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'ignore_sticky_posts'=> 1
      );
      $my_query = new WP_Query($args);
      if ( $my_query->have_posts() ) {
        echo "<li><div>$tax_term->name</div>";
        echo "<ul>";
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <li><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php  $delta_article_number = get_post_meta( get_the_ID( ), 'delta_article_number', true );  echo $delta_article_number;  ?> <?php the_title(); ?></a></li>
          <?php
        endwhile;
        echo "</ul></li>";
      }

    }
  }
  wp_reset_postdata();  wp_reset_query();
  ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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