Forums

foreach wp_query and get_terms (3 posts)

  1. pakpenyo
    Member
    Posted 10 months ago #

    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.

  2. pakpenyo
    Member
    Posted 10 months ago #

    anybody?

  3. pakpenyo
    Member
    Posted 10 months ago #

    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

Reply

You must log in to post.

About this Topic