WordPress.org

Ready to get started?Download WordPress

Forums

wordpress taxonomy query? (2 posts)

  1. monzu02
    Member
    Posted 10 months ago #

    i need a wordpress taxonomy query. let me explain what i am actually looking for. for ex i have taxonomy call product_cat and that product cat have 4 sub categories

    1) sub-cat-1

    2) sub-cat-2

    3) sub-cat-3

    4) sub-cat-4

    Now all sub-categories have 4 products

    a) product a b) product b c) product c d) product d

    now i need a query loop that will show is this way below

    1) sub-cat-1

    a) product a
    b) product b
    c) product c
    d) product d

    2) sub-cat-2

    a) product a
    b) product b
    c) product c
    d) product d

    3) sub-cat-3

    a) product a
    b) product b
    c) product c
    d) product d

    4) sub-cat-4

    a) product a
    b) product b
    c) product c
    d) product d

    Any idea how do i do that?

  2. monzu02
    Member
    Posted 10 months ago #

    i get a code its working for category but i need it for taxonomy

    //for each category, show all posts
    $cat_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => -1,
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories

Reply

You must log in to post.

About this Topic