Permalink of a custom post type

I am trying to get the link to a custom post type – Video. I have achieved this by doing:

get_post_type_archive_link( 'video' );

This returns http://mylink.co.uk/video which is brillant and exactly what I am looking for. However, when I click onto a custom post type category for example…LIVE and it loads the filtered results, the script link using get_post_type_archive_link( 'video' ); now changes to the LIVE category link showing http://mylink.co.uk/category/live/.

Read More

What is wrong?

UPDATE

function custom_post_type_video() {

    $labels = array(
        'name'                => _x( 'Videos', 'Post Type General Name', 'text_domain' ),
        'singular_name'       => _x( 'Video', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'           => __( 'Video', 'text_domain' ),
        'parent_item_colon'   => __( 'Parent Video:', 'text_domain' ),
        'all_items'           => __( 'All Video', 'text_domain' ),
        'view_item'           => __( 'View Video', 'text_domain' ),
        'add_new_item'        => __( 'Add New Video', 'text_domain' ),
        'add_new'             => __( 'New Video', 'text_domain' ),
        'edit_item'           => __( 'Edit Video', 'text_domain' ),
        'update_item'         => __( 'Update Video', 'text_domain' ),
        'search_items'        => __( 'Search Videos', 'text_domain' ),
        'not_found'           => __( 'No Videos found', 'text_domain' ),
        'not_found_in_trash'  => __( 'No Videos found in Trash', 'text_domain' ),
    );
    $args = array(
        'label'               => __( 'Video', 'text_domain' ),
        'description'         => __( 'Video information pages', 'text_domain' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'menu_icon'           => '',
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );
    register_post_type( 'Video', $args );

add_action( 'init', 'my_taxonomies_product', 0 );
// Initialize Taxonomy Labels
    $labels = array(
        'name' => _x( 'Categories', 'taxonomy general name', 'text_domain' ),
        'singular_name' => _x( 'Category', 'taxonomy singular name', 'text_domain' ),
        'search_items' =>  __( 'Search Types', 'text_domain' ),
        'all_items' => __( 'All Categories', 'text_domain' ),
        'parent_item' => __( 'Parent Category', 'text_domain' ),
        'parent_item_colon' => __( 'Parent Category:', 'text_domain' ),
        'edit_item' => __( 'Edit Categories', 'text_domain' ),
        'update_item' => __( 'Update Category', 'text_domain' ),
        'add_new_item' => __( 'Add New Category', 'text_domain' ),
        'new_item_name' => __( 'New Category', 'text_domain' ),
    );

    // Register Custom Taxonomy
    register_taxonomy('tagvideo',array('video'), array(
        'hierarchical' => true, // define whether to use a system like tags or categories
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'cat-video' ),
    ));

    }


// Hook into the 'init' action
add_action( 'init', 'custom_post_type_video', 0 );

Related posts

Leave a Reply

1 comment

  1. I don’t know why is it so. I read the code (both yours and WordPress’ source code) and didn’t find why is it so. I can tell you only two things that might or might not be helpful:-

    First

    This line:-

    register_post_type( 'Video', $args );
    

    should be like this:-

    register_post_type( 'video', $args ); // small v
    

    Second

    One quick and dirty workaround that you can do is to ‘hard-code’ the video post type archive link. Try inserting this code in your functions.php:-

    function video_post_type_archive_link( $link, $post_type ) {
       if( $post_type === 'video' ) {
          $link = 'http://mylink.co.uk/video' // <-- this should be link to 'video' post type archives
       }
       return $link;
    }
    add_filter('post_type_archive_link', 'video_post_type_archive_link', 10, 2);
    

    Now, whenever you’ll call this:

    get_post_type_archive_link( 'video' );
    

    You’ll get:

    http://mylink.co.uk/video
    

    Only for video custom post type.