• I have a custom post type called “project” and a list of 8 CPT categories. I am using the genesis framework to build my site. I have created a custom loop that pulls the project posts to a page, but I want to be able to load the page by taxonomy. Right now no matter which category I select, all posts show up. I know I need to create an array that pulls the taxonomy, but I’m still learning PHP and not 100% sure how to write it. Can anyone assist?
    My code is here:
    https://pastebin.com/NVnRBr3d

    Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, @plop_suey.

    Welcome to the WordPress support forums.

    Checking your loop function, you’ll need to add ‘category_name’ to your $args array.

    The ‘category_name’ parameter works with the Category slug not the actual name.

    So if your category is called: “Potato Chips” it would be like this:

      $args = array(
            'post_type'      => 'project',
            'posts_per_page' => 12,
            'post_status'    => 'publish',
            'category_name'  => 'potato-chips',
            'paged'          => get_query_var( 'paged' )
        );

    Hope that helps!

    Moderator bcworkz

    (@bcworkz)

    To limit posts by taxonomy term, add the “tax_query” argument to your query arguments array. Follow the examples carefully. The required nested array structure is not very intuitive in some cases.

    The remaining issue is how the tax_query code can know what term you selected. So, how are you selecting terms for posts this page is supposed to display?

    Hi plop_suey,

    Please take a look on this link https://wordpress.stackexchange.com/questions/84921/how-do-i-query-a-custom-post-type-with-a-custom-taxonomy

    Hopefully, it will solve your problem.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom loop to load CPT by category?’ is closed to new replies.