Custom Post Type with Custom Taxonomy returns no record

I have a bit of a puzzler here. I went through the whole forum for answers and couldn’t find what I was looking for. I have a custom post type of “blog” and taxonomy of “blog_post.” For some reason, running a query with a taxonomy term returns no record.

Things I have checked:

“blog” is set to public, publicly_queryable, and NOT exclude_from_search
“blog_types” is registered as a taxonomy of “blog”

Below are how they are registered under CPT UI.

Custom Post Type “blog”:

function cptui_register_my_cpts_blog() {

/**
* Post Type: Blog.
*/

$labels = array(
“name” => __( “Blog”, “testsite” ),
“singular_name” => __( “Blog Post”, “testsite” ),
);

$args = array(
“label” => __( “Blog”, “testsite” ),
“labels” => $labels,
“description” => “”,
“public” => true,
“publicly_queryable” => true,
“show_ui” => true,
“show_in_rest” => false,
“rest_base” => “”,
“has_archive” => true,
“show_in_menu” => true,
“exclude_from_search” => false,
“capability_type” => “post”,
“map_meta_cap” => true,
“hierarchical” => false,
“rewrite” => array( “slug” => “blog”, “with_front” => true ),
“query_var” => true,
“menu_icon” => “dashicons-media-document”,
“supports” => array( “title”, “revisions” ),
);

register_post_type( “blog”, $args );
}

add_action( ‘init’, ‘cptui_register_my_cpts_blog’ );

Custom Taxonomy “blog_types”:

function cptui_register_my_taxes_blog_types() {

/**
* Taxonomy: Blog Types.
*/

$labels = array(
“name” => __( “Blog Types”, “mammothrestoration” ),
“singular_name” => __( “Blog Type”, “mammothrestoration” ),
“menu_name” => __( “Update Blog Types”, “mammothrestoration” ),
);

$args = array(
“label” => __( “Blog Types”, “mammothrestoration” ),
“labels” => $labels,
“public” => true,
“hierarchical” => false,
“label” => “Blog Types”,
“show_ui” => true,
“show_in_menu” => true,
“show_in_nav_menus” => false,
“query_var” => true,
“rewrite” => array( ‘slug’ => ‘blog_types’, ‘with_front’ => true, ),
“show_admin_column” => false,
“show_in_rest” => false,
“rest_base” => “”,
“show_in_quick_edit” => false,
);
register_taxonomy( “blog_types”, array( “blog” ), $args );
}

add_action( ‘init’, ‘cptui_register_my_taxes_blog_types’ );

Here is how I am querying for the “blog_types” term “tips”:

$args = array(
‘post_type’ => ‘blog’,
‘posts_per_page’ => -1,
‘tax_query’ => array(
array(
‘taxonomy’ => ‘blog_types’,
‘field’ => ‘slug’,
‘terms’ => ‘tips’,
),
),
);

// Custom query.
$query = new WP_Query( $args );

Thanks in advance for anyone who stops by with tips/help.

Read more here:: Custom Post Type with Custom Taxonomy returns no record

Leave a Reply

Your email address will not be published. Required fields are marked *