0
votes

I created custom post type "testimonials" with custom taxomies it works well except of sinbgle page, when I click on permalink it shows "not found".

Here is my code for custom post types/taxonomies:

function testimonials_custom_post_type()
{
$labels = array(
    'name' => _x('Testimonials', 'Post type general name'),
    'singular_name' => _x('Testimonial', 'Post type singular name'),
    'add_new' => _x('Add new Testimonial', 'Grower'),
    'add_new_item' => __('Add new Testimonial'),
    'edit_item' => __('Edit Testimonial'),
    'new_item' => __('New Testimonial'),
    'all_items' => __('All Testimonials'),
    'view_item' => __('View Testimonial'),
    'search_items' => __('Search Testimonials'),
    'not_found' => __('No testimonials found'),
    'not_found_in_trash' => __('No testimonials found in Trash'),
    'parent_item_colon' => '',
);

$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => false,
    'query_var' => false,
    'rewrite' => true,
    'capability_type' => 'post',
    'has_archive' => false,
    'hierarchical' => false,
    'exclude_from_search' => false,
    'supports' => array('title', 'editor', 'thumbnail' ),
    'menu_position' => 6,
    'menu_icon'   => 'dashicons-id',
    'taxonomies' => array( 'subjects' ),
);

register_post_type('testimonials', $args);
}

add_action('init', 'testimonials_custom_post_type');

    /*register custom taxonomies for testimonials*/

add_action( 'init', 'create_testimonials_taxonomies', 0 );
function create_testimonials_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
    'name'              => _x( 'Subjects', 'subjects', 'textdomain' ),
    'singular_name'     => _x( 'Subject', 'subject', 'textdomain' ),
    'search_items'      => __( 'Search Subject', 'textdomain' ),
    'all_items'         => __( 'All Subjects', 'textdomain' ),
    'edit_item'         => __( 'Edit Subject', 'textdomain' ),
    'update_item'       => __( 'Update Subject', 'textdomain' ),
    'add_new_item'      => __( 'Add new Subject', 'textdomain' ),
    'new_item_name'     => __( 'New Category Subject', 'textdomain' ),
    'menu_name'         => __( 'Subject', 'textdomain' ),
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => false,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'subjects' ),
);

register_taxonomy( 'subjects', array( 'testimonials' ), $args );
   }
   /*register custom taxonomies for testimonials*/

I tried to use flush_rewrite_rules( false ); and tried to update permalinks in wp admin panel it's still not working

For custom post type "testimonials" I created single-testimonials.php in my child theme

Thank you very much for any help!

2

2 Answers

1
votes

To fix my bug I had to set 'publicly_queryable' to 'true' and it works now ))

0
votes

You could try to create taxonomy-subjects.php and refresh your permalinks after you try each time.