1

I am using Underscores starter theme and I've created a custom post type video.

$args = array(
    'label'                 => __( 'Video', 'text_domain' ),
    'description'           => __( 'Videos', 'text_domain' ),
    'labels'                => $labels,
    'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields', ),
    'taxonomies'            => array( 'category', 'post_tag' ),
    'hierarchical'          => false,
    'public'                => true,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 5,
    'menu_icon'             => 'dashicons-video-alt2',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'can_export'            => true,
    'has_archive'           => true,
    'exclude_from_search'   => false,
    'publicly_queryable'    => true,
    'capability_type'       => 'post',
);
register_post_type( 'video', $args );

I am able to display the latest posts from video on the homepage (which is a custom page template) but when I visit the video link, I get Oops! That page can’t be found!

I've created a new file single-video.php and inside I'm getting the video template

get_template_part( 'template-parts/content', 'video' );

I've also created another file content-video.php which lives inside template-parts folder and is the copy of the original content.php file

But it's not working, I'm still getting Page Not Found when I visit the video url.

2 Answers 2

6

In your dashboard go to settings/permalinks. Hit save. You should be able to see your cpts now.

6
  • Thank you that solved it. Do I need the single-video.php though? Because if I remove it, the page still loads fine.
    – Halnex
    Apr 6, 2017 at 17:31
  • 2
    It's not exactly necessary to have a single-video.php template unless you want to change the code for that post type. If it's not specified, it'll default to the single.php template file in the theme. Check out the WordPress template hierarchy for more info developer.wordpress.org/themes/basics/template-hierarchy
    – Ian
    Apr 6, 2017 at 17:33
  • @ian beat me to it
    – rudtek
    Apr 6, 2017 at 17:40
  • 2
    to be clear. if you want ALL single posts of every type to be different than no, just change the single.php. If you want videos to have a different appearance of their own when viewed then make changes to single-video.php
    – rudtek
    Apr 6, 2017 at 17:41
  • 1
    No, not different style, but different code structure. Lets say you don't want your video post type to have a sidebar, but the single.php template uses a sidebar. So you don't end up affecting all other regular posts, you could create a single-video.php template without a sidebar and be good. For styles, you can for the most part target a post type specifically if you need to adjust styles there, regardless of the template being used.
    – Ian
    Apr 6, 2017 at 17:42
2

you should create content-video.php inside template-parts folder.

And try resetting permalinks. That means:

Go to Settings > Permalinks

Change Permalink setting to plain and save

Change permalink settings to your desired one again and save

It should fix the issue.

4
  • no need to make any changes on the permalinks page. Just hitting save is enough
    – rudtek
    Apr 6, 2017 at 17:27
  • May be. I usually solve the way I've described. Apr 6, 2017 at 17:30
  • your way works...just extra steps
    – rudtek
    Apr 6, 2017 at 17:39
  • You don't even have to hit save, just visiting the permalinks page flushes the rules.
    – Milo
    Apr 6, 2017 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.