קסטום פוסט חדש CPT

קסטום פוסט טייפ ללא טקסונומיות

/*Custom Post type start*/
add_action('init', 'gs_post_type_testimonials');
function gs_post_type_testimonials() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);
$labels = array(
'name' => _x('Testimonials', 'plural'),
'singular_name' => _x('Testamonial', 'singular'),
'menu_name' => _x('Testimonials', 'admin menu'),
'name_admin_bar' => _x('Testimonials', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New Testimonial'),
'new_item' => __('New Testimonial'),
'edit_item' => __('Edit Testimonial'),
'view_item' => __('View Testimonial'),
'all_items' => __('All Testimonial'),
'search_items' => __('Search Testimonial'),
'not_found' => __('No Testimonial found.'),
);
$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'testimonials'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('testimonials', $args);
}

קסטום פוסט טייפ עם טקסונומיות

add_action( 'init', 'custom_post_type', 0 );
function custom_post_type() {
// Set UI labels for Custom Post Type
    $labels = array(
        'name'                => _x( 'מודעות דרושים', 'Post Type General Name', 'twentythirteen' ),
        'singular_name'       => _x( 'עובד', 'Post Type Singular Name', 'twentythirteen' ),
        'menu_name'           => __( 'דרושים', 'twentythirteen' ),
        'parent_item_colon'   => __( 'Parent Movie', 'twentythirteen' ),
        'all_items'           => __( 'כל המודעות', 'twentythirteen' ),
        'view_item'           => __( 'View Movie', 'twentythirteen' ),
        'add_new_item'        => __( 'הוספת מודעה חדשה', 'twentythirteen' ),
        'add_new'             => __( 'מודעה חדשה', 'twentythirteen' ),
        'edit_item'           => __( 'Edit Movie', 'twentythirteen' ),
        'update_item'         => __( 'Update Movie', 'twentythirteen' ),
        'search_items'        => __( 'Search Movie', 'twentythirteen' ),
        'not_found'           => __( 'Not Found', 'twentythirteen' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'twentythirteen' ),
    );
     
// Set other options for Custom Post Type
     
    $args = array(
        'label'               => __( 'jobs', 'twentythirteen' ),
        'description'         => __( 'Movie news and reviews', 'twentythirteen' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'hierarchical'        => true,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 25,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
         
        // This is where we add taxonomies to our CPT
        //'taxonomies'          => array('topics'),
    );
     
    // Registering your Custom Post Type
    register_post_type( 'jobs', $args );
	
	//
	 $labels = array(
		'name' => _x( 'הוספת קטגוריית מודעות', 'taxonomy general name' ),
		'singular_name' => _x( 'עובד', 'taxonomy singular name' ),
		'search_items' =>  __( 'חיפוש בדרושים' ),
		'all_items' => __( 'כל קטגוריות המודעות' ),
		'parent_item' => __( 'קטגוריית מודעות' ),
		'parent_item_colon' => __( 'Parent Topic:' ),
		'edit_item' => __( 'Edit Topic' ), 
		'update_item' => __( 'Update Topic' ),
		'add_new_item' => __( 'Add New Topic' ),
		'new_item_name' => __( 'New Topic Name' ),
		'menu_name' => __( 'קטגורית דרושים' ),
	  ); 
	register_taxonomy('job_category',array('jobs'), array(
		'hierarchical' => true,	
		'labels' => $labels,
		'show_ui' => true,
		'show_admin_column' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'דרושים' ),
  	));
 
}

מידע נוסף אפשר למצוא בקישור הבא

https://crunchify.com/how-to-create-wordpress-custom-post-type-cpt-and-taxonomy-hello-world-tutorial-tips-and-tricks/

כתיבת תגובה