Custom Post Type – No Results Found

Question

I’ve recently taken over management of a page that uses a custom post type. The owners of the page developed an iOS app that is using information pulled from the site via the REST API, so I added some show_in_rest to the arguments in our functions.php file. Since doing that we’ve lost the ability to view posts with this custom post type unless we’re logged in as Administrator, Editor, etc…

Here is the code from our functions.php that registers things.

 // Create Instructor Video Post Type

if (!function_exists('register_instructor_videos')) :
    function register_instructor_videos()
    {
        $labels = array( 
            'name'               => 'Instructor Videos',
            'singular_name'      => 'Instructor Video',
            'add_new'            => 'Add New  Video',
            'add_new_item'       => 'Add New  Video',
            'edit_item'          => 'Edit  Instructor Video',
            'new item'           => 'New Video',
            'all_items'          => 'All Instructor Videos',
            'view_item'          => 'View Instructor Video',
            'search_items'       => 'Search Instructor Videos',
            'not_found'          => 'No Instructor Videos found',
            'not_found_in_trash' => 'No Instructor Videos found in Trash',
            'menu_name'          => 'Instructor Videos'
        );

        $args = array(
            'labels'      => $labels, 
            'public'      => true, 
            'taxonomies'  => array(), 
            'rewrite'     => apply_filters('et_project_posttype_rewrite_args', array(
                'feeds'      => true,
                'slug'       => 'instructor-videos',
                'with_front' => false,
            )), 
            'hierarchical' => false, 
            'has_archive' => true, 
            'supports'    => array( 
                'title',
                'editor',
                'thumbnail',
                'custom-fields',
                'comments',
                'excerpt',
                'revisions'
            ),
            'menu_icon' => 'dashicons-video-alt2', 
            'menu_position' => null, 
            'show_in_rest' => true, 
            'publicly_queryable' => true,
        );

        // Tell WordPress about our new post type
        register_post_type('instructor-videos', apply_filters('et_project_posttype_args', $args));


        $labels = array(
            'name'              => esc_html__('Instructor Videos Categories', 'et_builder'),
            'singular_name'     => esc_html__('Instructor Videos Category', 'et_builder'),
            'search_items'      => esc_html__('Search Categories', 'et_builder'),
            'all_items'         => esc_html__('All Categories', 'et_builder'),
            'parent_item'       => esc_html__('Parent Category', 'et_builder'),
            'parent_item_colon' => esc_html__('Parent Category:', 'et_builder'),
            'edit_item'         => esc_html__('Edit Category', 'et_builder'),
            'update_item'       => esc_html__('Update Category', 'et_builder'),
            'add_new_item'      => esc_html__('Add New Category', 'et_builder'),
            'new_item_name'     => esc_html__('New Category Name', 'et_builder'),
            'menu_name'         => esc_html__('Categories', 'et_builder'),

        );
        
        $args = array(
            'hierarchical'          => true,
            'labels'                => $labels,
            'show_ui'               => true,
            'show_admin_column'     => true,
            'query_var'             => true,
            'rewrite'               => array( 'slug' => 'genre' ),
            'show_in_rest'          => true,
            'rest_base'             => 'instructor-videos_category',
            'rest_controller_class' => 'WP_REST_Terms_Controller',
        );

        register_taxonomy('instructor_videos_category', array('instructor-videos'), $args);
        
        function my_plugin_rest_route_for_term( $route, $term ) {
             if ( $term->taxonomy === 'instructor-videos-category' ) {
                 $route = '/wp/v2/instructor-videos-category/' . $term->term_id;
             }
 
            return $route;
        }
        add_filter( 'rest_route_for_term', 'my_plugin_rest_route_for_term', 10, 2 );

        $labels = array(
            'name'              => esc_html__('Instructor Videos Tags', 'et_builder'),
            'singular_name'     => esc_html__('Instructor Videos Tag', 'et_builder'),
            'search_items'      => esc_html__('Search Tags', 'et_builder'),
            'all_items'         => esc_html__('All Tags', 'et_builder'),
            'parent_item'       => esc_html__('Parent Tag', 'et_builder'),
            'parent_item_colon' => esc_html__('Parent Tag:', 'et_builder'),
            'edit_item'         => esc_html__('Edit Tag', 'et_builder'),
            'update_item'       => esc_html__('Update Tag', 'et_builder'),
            'add_new_item'      => esc_html__('Add New Tag', 'et_builder'),
            'new_item_name'     => esc_html__('New Tag Name', 'et_builder'),
            'menu_name'         => esc_html__('Tags', 'et_builder'),
        );

        register_taxonomy('instructor-videos_tag', array('instructor-videos'), array(
            'hierarchical'      => false,
            'labels'            => $labels,
            'show_ui'           => true,
            'show_admin_column' => true,
            'query_var'         => true,

        ));
    }
endif;

// Call our new posty type function
add_action('init', 'register_instructor_videos');

I feel like I must be missing something simple, but I’ve been reading posts here with this issue all afternoon and I can’t seem to find anything that makes our pages publicly viewable.

0
Jason Cathcart 3 months 0 Answers 22 views 0

Leave an answer