• Hi Guys and Gals,

    I’ve finally decided to ask for some help as I’ve been googling, searching and bashing my head against a wall for ages now.

    I’ve made a custom post type, called ‘Videos’ and a taxonomy for that post type called ‘Video Categories’ both of these bits work perfectly in the back end.

    By default when you make a video category, and put some posts in it, they all show up perfectly in the admin side, but when you click ‘View’ on that category by default it shows no posts.

    Some extensive googling reveals this is because it’s querying normal posts not my custom post type so I had a go at trying to fix this.

    The two closest ways I came to fixing this where querying an individual taxonomy but this is no good as I want to be able to create more categories as the site grows and I don’t want to have to make a new page template for every category.

    I also got it posting every post in the custom post type, but not abiding by the category taxonomy.

    Anyone got any ideas of the best way to do this? At a loss here!

Viewing 1 replies (of 1 total)
  • Thread Starter JackNexusGx

    (@jacknexusgx)

    If it helps, here is how I’ve registered my post type and taxonomy:

    add_action( 'init', 'videos_post_type' );
    function videos_post_type() {
        $labels = array(
            'name' => 'Videos',
            'singular_name' => 'Video',
            'add_new' => 'Add New Video',
            'add_new_item' => 'Add New Video',
            'edit_item' => 'Edit Video',
            'new_item' => 'New Video',
            'view_item' => 'View Video',
            'search_items' => 'Search Videos',
            'not_found' =>  'No Videos found',
            'not_found_in_trash' => 'No Videos in the trash',
            'parent_item_colon' => '',
        );
    
        register_post_type( 'video', array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'exclude_from_search' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 10,
            'supports' => array( 'title', 'editor', 'thumbnail' ),
            'register_meta_box_cb' => 'add_video_meta_boxes', // Callback function for custom metaboxes
    
        ) );
    }
    
    add_action( 'init', 'create_video_hierarchical_taxonomy', 0 );
    function create_video_hierarchical_taxonomy() {
    
      $labels = array(
        'name' => _x( 'Video Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Categories' ),
        'all_items' => __( 'Video Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit Category' ),
        'update_item' => __( 'Update Category' ),
        'add_new_item' => __( 'Add New Category' ),
        'new_item_name' => __( 'New Category Name' ),
        'menu_name' => __( 'Categories' ),
      );   
    
    // Now register the taxonomy
    
      register_taxonomy('video-category',array('video'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'public' => true,
        'exclude_from_search' => false,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'video-category' ),
      ));
    }
Viewing 1 replies (of 1 total)

The topic ‘Creating a custom post-type taxonomy post-page’ is closed to new replies.