Support » Themes and Templates » querying "products" custom post type stacked by "kind" taxonomies

  • Resolved fpsdf


    Hello everyone,

    I need to make a page (well, not necessarily a wordpress default page) where i can see all the products (a custom post type i’ve made) ordered by kind (a taxonomy that i’ve also made).

    Like this:

    Pigmentos nacarados
    Pigmentos inorgânicos óxidos de ferro
    Pigmentos orgânicos
    AC Colours
    DC Colours
    IC Colours

    Ecotint / Econyl TS / Leomix
    Corantes liquidos em DPM/PM GlobalTint
    Corantes universais C e SU GlobalTint

    TiO2 R-403
    TiO2 R-2295
    TiO2 R-298

    (oh, nevermind the language, it’s portuguese)

    What would be the best technique?

    Thank you so much for your help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Something like this:
    Create a copy of archive.php and call it archive-products.php.
    Edit achive-products.php and just before the end of the loop code like this:

    $args = array('post_type' => 'products',
       'tax_query' => array (
          array ( 'taxonomy' => 'pigments',
             'field'    => 'id',
             'terms'    => get_the_ID()  )));
    $the_query = new WP_Query ($args);
    while ( $the_query->have_posts() ) : $the_query->the_post();
          if ($i==0) { echo "<h3>Score(s)</h3>";  $i++; }

    I learnt this just 2 weeks ago and I’m passing on the karma …!

    No scrub that, I was solving another problem. Sorry!

    no problem, nprior. I thank you anyway!

    Take a look at creating taxonomy-kind.php (template hierarchy in the Docs), based on archive.php, then add this sort of code in just before the end of the loop:
    $args = array(‘post_type’ => ‘products’,
    ‘tax_query’ => array (
    array ( ‘taxonomy’ => ‘kind’,
    ‘field’ => ‘id’,
    ‘terms’ => get_the_ID() )));
    $the_query = new WP_Query ($args);
    while ( $the_query->have_posts() ) : $the_query->the_post(); the_title();

    for some reason, it is not using taxonomy-kind.php. It skips to index.php has a discussion about the taxonomy template. Some mixed experiences there.

    I’m trying some of this with a test site of mine. If I sort it out I’ll report back.

    you’re very kind! thank you so much.
    please don’t spend your working time because of me!

    Anyway, i think this could work as a loop within a loop: the “kinds” would be looped and, within each “kind”, respective “products” would be also looped.

    I agree – I was hoping to find out how to make the taxonomy template work because that’s where your “kind” would loop automatically.

    It might be worth checking out Rachel Carden’s CPT-onomies plugin (who gave me that code in the first place) This effectively makes the taxonomy work more like a custom post type and there’s a special archive slug which makes it easy to do what you wanted.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘querying "products" custom post type stacked by "kind" taxonomies’ is closed to new replies.