Replies: 0
hi
i created custom post types by given coding , but custom post does not display in category.how can i display in category.plz guide me. coding is here
function custom_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
‘name’ => _x( ‘WordPresses’, ‘Post Type General Name’, ‘twentythirteen’ ),
‘singular_name’ => _x( ‘WordPress’, ‘Post Type Singular Name’, ‘twentythirteen’ ),
‘menu_name’ => __( ‘WordPresses’, ‘twentythirteen’ ),
‘parent_item_colon’ => __( ‘Parent WordPress’, ‘twentythirteen’ ),
‘all_items’ => __( ‘All WordPresses’, ‘twentythirteen’ ),
‘view_item’ => __( ‘View WordPress’, ‘twentythirteen’ ),
‘add_new_item’ => __( ‘Add New WordPress’, ‘twentythirteen’ ),
‘add_new’ => __( ‘Add New’, ‘twentythirteen’ ),
‘edit_item’ => __( ‘Edit WordPress’, ‘twentythirteen’ ),
‘update_item’ => __( ‘Update WordPress’, ‘twentythirteen’ ),
‘search_items’ => __( ‘Search WordPress’, ‘twentythirteen’ ),
‘not_found’ => __( ‘Not Found’, ‘twentythirteen’ ),
‘not_found_in_trash’ => __( ‘Not found in Trash’, ‘twentythirteen’ ),
);
// Set other options for Custom Post Type
$args = array(
‘label’ => __( ‘wordpresses’, ‘twentythirteen’ ),
‘description’ => __( ‘WordPress articles’, ‘twentythirteen’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘author’, ‘thumbnail’, ‘comments’, ‘revisions’, ‘custom-fields’, ),
‘hierarchical’ => false,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => true,
‘show_in_admin_bar’ => true,
‘menu_position’ => 2,
‘can_export’ => true,
‘has_archive’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘capability_type’ => ‘page’,
‘show_in_rest’ => true,
// This is where we add taxonomies to our CPT
‘taxonomies’ => array( ‘category’ ),
);
// Registering your Custom Post Type
register_post_type( ‘wordpresses’, $args );
// Set UI labels for Custom Post Type
$labels = array(
‘name’ => _x( ‘Dramas’, ‘Post Type General Name’, ‘twentythirteen’ ),
‘singular_name’ => _x( ‘Drama’, ‘Post Type Singular Name’, ‘twentythirteen’ ),
‘menu_name’ => __( ‘Dramas’, ‘twentythirteen’ ),
‘parent_item_colon’ => __( ‘Parent Drama’, ‘twentythirteen’ ),
‘all_items’ => __( ‘All Dramas’, ‘twentythirteen’ ),
‘view_item’ => __( ‘View Drama’, ‘twentythirteen’ ),
‘add_new_item’ => __( ‘Add New Drama’, ‘twentythirteen’ ),
‘add_new’ => __( ‘Add New’, ‘twentythirteen’ ),
‘edit_item’ => __( ‘Edit Drama’, ‘twentythirteen’ ),
‘update_item’ => __( ‘Update Drama’, ‘twentythirteen’ ),
‘search_items’ => __( ‘Search Drama’, ‘twentythirteen’ ),
‘not_found’ => __( ‘Not Found’, ‘twentythirteen’ ),
‘not_found_in_trash’ => __( ‘Not found in Trash’, ‘twentythirteen’ ),
);
// Set other options for Custom Post Type
$args = array(
‘label’ => __( ‘dramas’, ‘twentythirteen’ ),
‘description’ => __( ‘Drama reviews’, ‘twentythirteen’ ),
‘labels’ => $labels,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘author’, ‘thumbnail’, ‘comments’, ‘revisions’, ‘custom-fields’, ),
‘hierarchical’ => false,
‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => true,
‘show_in_admin_bar’ => true,
‘menu_position’ => 3,
‘can_export’ => true,
‘has_archive’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘capability_type’ => ‘page’,
‘show_in_rest’ => true,
// This is where we add taxonomies to our CPT
‘taxonomies’ => array( ‘category’ ),
);
// Registering your Custom Post Type
register_post_type( ‘dramas’, $args );
/* Hook into the ‘init’ action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( ‘init’, ‘custom_post_type’, 0 );
add_filter(‘pre_get_posts’, ‘query_post_type’);
function query_post_type($query)
{
if( is_category() ) {
$post_type = get_query_var(‘post_type’);
if($post_type)
$post_type = $post_type;
else
$post_type = array(‘nav_menu_item’, ‘post’, ‘wordpresses’); // don’t forget nav_menu_item to allow menus to work!
$query->set(‘post_type’,$post_type);
return $query;
}
}
{
if( is_category() ) {
$post_type = get_query_var(‘post_type’);
if($post_type)
$post_type = $post_type;
else
$post_type = array(‘nav_menu_item’, ‘post’, ‘dramas’); // don’t forget nav_menu_item to allow menus to work!
$query->set(‘post_type’,$post_type);
return $query;
}
}