0

I have created a custom post type using below code.

// Register Custom Post Type test-slider
function create_testslider_cpt() {

    $labels = array(
        'name' => _x( 'test-sliders', 'Post Type General Name', 'mydomain' ),
        'singular_name' => _x( 'test-slider', 'Post Type Singular Name', 'mydomain' ),
        'menu_name' => _x( 'test-sliders', 'Admin Menu text', 'mydomain' ),
        'name_admin_bar' => _x( 'test-slider', 'Add New on Toolbar', 'mydomain' ),
        'archives' => __( 'test-slider Archives', 'mydomain' ),
        'attributes' => __( 'test-slider Attributes', 'mydomain' ),
        'parent_item_colon' => __( 'Parent test-slider:', 'mydomain' ),
        'all_items' => __( 'All test-sliders', 'mydomain' ),
        'add_new_item' => __( 'Add New test-slider', 'mydomain' ),
        'add_new' => __( 'Add New', 'mydomain' ),
        'new_item' => __( 'New test-slider', 'mydomain' ),
        'edit_item' => __( 'Edit test-slider', 'mydomain' ),
        'update_item' => __( 'Update test-slider', 'mydomain' ),
        'view_item' => __( 'View test-slider', 'mydomain' ),
        'view_items' => __( 'View test-sliders', 'mydomain' ),
        'search_items' => __( 'Search test-slider', 'mydomain' ),
        'not_found' => __( 'Not found', 'mydomain' ),
        'not_found_in_trash' => __( 'Not found in Trash', 'mydomain' ),
        'featured_image' => __( 'Featured Image', 'mydomain' ),
        'set_featured_image' => __( 'Set featured image', 'mydomain' ),
        'remove_featured_image' => __( 'Remove featured image', 'mydomain' ),
        'use_featured_image' => __( 'Use as featured image', 'mydomain' ),
        'insert_into_item' => __( 'Insert into test-slider', 'mydomain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this test-slider', 'mydomain' ),
        'items_list' => __( 'test-sliders list', 'mydomain' ),
        'items_list_navigation' => __( 'test-sliders list navigation', 'mydomain' ),
        'filter_items_list' => __( 'Filter test-sliders list', 'mydomain' ),
    );
    $rewrite = array(
        'slug' => 'testslider',
        'with_front' => true,
        'pages' => true,
        'feeds' => true,
    );
    $args = array(
        'label' => __( 'test-slider', 'mydomain' ),
        'description' => __( 'custom post slider', 'mydomain' ),
        'labels' => $labels,
        'menu_icon' => 'dashicons-format-gallery',
        'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'author', 'comments', 'trackbacks', 'page-attributes', 'post-formats', 'custom-fields'),
        'taxonomies' => array('category'),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'can_export' => true,
        'has_archive' => true,
        'hierarchical' => false,
        'exclude_from_search' => false,
        'show_in_rest' => true,
        'publicly_queryable' => true,
        'capability_type' => 'post',
        'rewrite' => $rewrite,
    );
    register_post_type( 'testslider', $args );

}
add_action( 'init', 'create_testslider_cpt', 0 );

I am getting the output

enter image description here

This is my Add new slider

enter image description here

I have two issues

1) I created one test slider and a link is http://example.com/testslider/lorem-ipsum-dolor-sit-amet/ and when I click on this link then I am getting page not found.

2)I need a custom field on the Add New page where user can enter the Custom URL.

Would you help me out?

  • 1
    For 1) Try flushing the permalinks - just visit the Permalink Settings page. For 2) You can use the standard Custom Fields editor, a plugin like ACF or see add_meta_box() - there are examples on that page. – Sally CJ Nov 5 at 11:39
  • @SallyCJ, Let me check above links – Naren Verma Nov 5 at 11:45
  • Yes, First one is working. check ing second – Naren Verma Nov 5 at 11:49
  • Hopefully everything is going good.. but if you got stuck with coding the meta box, you can post another question. Just remember, ACF or other 3rd-party plugins are off-topic here.. – Sally CJ Nov 6 at 19:09
  • @SallyCJ, I am not using any plugin till now. Referring the google and youtube for creating an input field. – Naren Verma Nov 7 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.