Forums

Product Pages that Query Post Type and Taxonomy Group (4 posts)

  1. jrstaatsiii
    Member
    Posted 9 months ago #

    Hey All, thanks in advance for any guidance.

    I created a custom post type called 'products' Attached this post type I have two taxonomy groups: "Men's Category (mens-category) and "Women's Category (womens-category). What I am trying to accomplish, but have become vexed, is to create page templates for each taxonomy group.

    For the Men's Product Page I would like to target all posts from the product post type that are part of "mens-category" taxonomy group. I would like to do the same, respectively, for the women's taxonomy group.

    What would the correct arguments be to accomplish this? I have this in the wp query which is incorrect:

    $args = array('post_type' => 'product', 'taxonomy' => 'womens-category');

    Thanks!

    Rich

  2. peredur
    Member
    Posted 9 months ago #

    Maybe I'm not understanding what you want correctly, but don't you just want a number of category lists?

    You don't need multiple templates to create category lists. You just create the categories, create some posts in each category and then add the category(ies) to your Primary Navigation menu (or any other menu, I guess). The only thing you have to make sure of is that you are using a custom menu as your Primary Navigation menu (if your category lists are going to be accessed from there).

    Posts can be in multiple categories, so they can appear on multiple lists, if you want.

    You may need, hopefully in your child theme, to style the category lists a bit differently if they're not to your taste, or perhaps make a few alterations to the already existing template file(s). But you don't need separate taxonomies and multiple template files, as a rule.

    Unless of course I'm mistaken in what I understand you to need.

    Cheers

    PAE

  3. jrstaatsiii
    Member
    Posted 9 months ago #

    Hey PAE, thanks for the reply.

    Since I am using CPT's and Taxonomie to build an online store, I need to have the product CPT to render a different layout. I am just querying for product type, essentially, and this is what I have so far that works (less intuitive) and what I would like to have to make it more dynamic. This is built in the genesis framework, so you may notice some code not directly related to WordPress

    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'womens_custom_loop');
    function womens_custom_loop() {
    
    global $paged;
        $args = array(
        'post_type' => 'product',
        'tax_query' => array(
            array(
                'taxonomy' => 'womens-category',
                'field' => 'slug',
                'terms' => 'beanies','hoodies'
            )
        )
    );
    	genesis_custom_loop( $args );
    }

    Notice 'terms' => 'beanies','hoodies'

    I'd really like to replace with a variable based on get_terms() but what I have done so far has not worked:

    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'womens_custom_loop');
    
    $terms = get_terms('womens-category');
    
    function womens_custom_loop() {
    
    global $paged;
        $args = array(
        'post_type' => 'product',
        'tax_query' => array(
            array(
                'taxonomy' => 'womens-category',
                'field' => 'slug',
                'terms' => $terms
            )
        )
    );
    	genesis_custom_loop( $args );
    }

    This returns a "Sorry, no posts matched your criteria."

    Any thoughts?

    Rich

  4. peredur
    Member
    Posted 9 months ago #

    Sorry Rich. I'm going to have to bow out gracefully here. There's too many things I'm not familiar with for me to be of much help.

    (As a programmer, though, I'd be starting by checking exactly what get_terms() is returning, if you can find a way of capturing it and printing it to the screen or something)

    Best of luck.

    Cheers

    PAE

Reply

You must log in to post.

About this Topic

Tags

No tags yet.