• Resolved thelittlehand

    (@thelittlehand)


    I have searched for so long before posting.

    I have created a custom post-type “products” and there are few “product-category” likes books, electronics and games.

    I can list all products in archive-products.php. Then, I created a “taxonomy-product-category.php” template to show the posts after clicking on the “get_term_link()” of a specific product category.

    But now all the three pages below shows the same list of posts of ALL products but not corresponding product category:
    http://mydomain.com/product-category/books/
    http://mydomain.com/product-category/electronics/
    http://mydomain.com/product-category/games/

    I guess there is something wrong with the WP_Query in the taxonomy-product-category.php:

    <?php
    $new_query = new WP_Query();
    $new_query->query('post_type=products');
    ?>
    
    <?php while ($new_query->have_posts()) : $new_query->the_post(); ?>
    
      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    
    <?php endwhile; ?>

    Please kindly help~~

Viewing 5 replies - 1 through 5 (of 5 total)
  • Your query does not select a product-category.

    Since I can’t see all of your code, this is somewhat of a guess, but I think you could do this.

    Set a Custom Field named ‘product-category’ on each of your three pages. Set its value to be the same as the product-category to show on that page. For example, on http://mydomain.com/product-category/books/, set it to ‘books’.

    Then change the code in your taxonomy-product-category.php to this (UNTESTED):

    <?php
    $product_category = get_post_meta($post->ID,'product-category',true);
    $new_query = new WP_Query();
    $new_query->query("post_type=products&product-category=$product_category");
    ?>
    Thread Starter thelittlehand

    (@thelittlehand)

    Sorry for the delay.
    Thanks, vtxyzzy for the big help.
    Although I didn’t get your suggestion work, I can see the hint.
    Now I have removed the WP_Query and use the parent query. It works perfectly and show the post of current category only.

    http://pastebin.com/82k3W1mV

    On the other hand, however, I don’t know how can I have them in 4-post a page.

    Many Thanks!

    On the other hand, however, I don’t know how can I have them in 4-post a page.

    Sorry, I do not understand what you want. Please explain more.

    Thread Starter thelittlehand

    (@thelittlehand)

    I was wondering how to set the post per page.
    Now I see it from Setting.
    Many thanks!

    You are welcome!

    If your problem has been solved, please use the dropdown on the right to mark this topic ‘Resolved’ so that anyone else with this question can see that there is a solution.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Can't list posts by custom terms’ is closed to new replies.