How to filter custom post types by custom category taxonomy


I’m running WordPress 4.6.1 and I am trying to learn how to filter custom post types by a category taxonomy process. This is very helpful as non-technical folks can easily filter custom post type posts by category in the admin.

This is my setup…

  1. I’m building a child theme off of tweentysixteen

  2. I created and registered a custom post type in my child functions.php file like this…

    function prowp_register_my_post_types() {
            'labels' => array (
                'name' => 'Products',
                'singular_name' => 'Product',
                'add_new' => 'Add New Product',
                'add_new_item' => 'Add New Product',
                'edit_item' => 'Edit this Product',
                'new_item' => 'New Product',
                'all_items' => 'All My Products'
            'public' => true,
            'show_ui' => true,
            'taxonomies'  => array ( 
            'supports' =>  array (
  3. I am now using my registered custom post type in my child index.php file like this:

    $pargs = array(
            'post_per_page' => '-1',
            'post_type' => 'products',
            'tax_query' => array(
                'taxonomy' => 'category',
                'field'    => 'slug',
                'terms' => 'Specials'
        $myProducts = new WP_Query($pargs);
        while ( $myProducts->have_posts() ) : $myProducts->the_post();
  4. Finally, from wp-admin, I then created my custom post types posts and assigned the category “Specials” to “one” of my posts. The others are uncategorized. And every page is published.

…But for some reason, my browser page is listing all my posts from this custom post type, and not just Specials. I’m I doing something wrong?

klewis 1 month 0 Answers 8 views 0

Leave an answer