• I have problem with the loop in page. Here is my code:

    <ul>
    	<?php
    		$terms = get_terms('product');
    		foreach ($terms as $term) {
    			$views = new WP_Query(array('post_type' => 'project', 'post_per_page' => 20));
    			while ($views->have_posts()) : $views->the_post(); ?>
    			<li class="rounded">
    				<?php if (function_exists('get_the_image'))
    				$views_img = get_the_image( array( 'image_scan' => true, 'format' => 'array', 'size' => 'medium','width' => '128' ) ); ?>
    				<a href="<?php echo get_term_link($term->slug, 'product'); ?>" title="">
    					<img src="<?php echo home_url( '/' ); ?>wp-content/uploads/timthumb.php?w=120&h=64&zc=1&src=<?php echo $views_img[url]; ?>" alt=""/>
    				</a>
    			</li>
    	<?php endwhile; } wp_reset_query(); ?>
    </ul>

    It must show the recent post from “product” custom taxonomy. And the “post permalink” is go to taxonomy category.

    The problem is with the post. It’s showing double for each post with the random taxonomy category url.

    I know that’s problem with the loop, but i don’t know how to fix it.
    Sorry about my bad english.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pakpenyo

    (@pakpenyo)

    anybody?

    Thread Starter pakpenyo

    (@pakpenyo)

    i’ve done trying with this code from this forum but it’s the same, double post.

    <?php
    //for a given post type, return all
    $tax = 'product';
    $terms = get_terms($tax);
    if ($terms) {
      foreach ($terms as $term) {
        $args=array(
          'post_type' => 'project',
          //'$tax' => $tax_term->slug,
    	  '$tax' => $tax_term->slug,
          'post_status' => 'publish',
          'posts_per_page' => 20,
          'caller_get_posts'=> -1
        );
    
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of '.$post_type . ' where the taxonomy '. $tax . '  is '. $tax_term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php echo get_term_link($term->slug, 'product'); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php
          endwhile;
        }
        wp_reset_query();
      }
    }
    ?>

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘foreach wp_query and get_terms’ is closed to new replies.