danstramer

Custom post type and taxonomy | functions.php | Wordpress

Apr 9th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.59 KB | None | 0 0
  1. add_action( 'init', 'register_cpt_product' );
  2. function register_cpt_product() {
  3.     $labels = array(
  4.     'name' => _x( 'מוצרים', 'products' ),
  5.     'singular_name' => _x( 'מוצרים', 'products' ),
  6.     'add_new' => _x( 'הוסף חדש', 'products' ),
  7.     'add_new_item' => _x( 'הוסף מוצר', 'products' ),
  8.     'edit_item' => _x( 'ערוך', 'products' ),
  9.     'new_item' => _x( 'חדש', 'products' ),
  10.     'view_item' => _x( 'הצג', 'products' ),
  11.     'search_items' => _x( 'חפש', 'products' ),
  12.     'not_found' => _x( 'לא נמצא', 'products' ),
  13.     'not_found_in_trash' => _x( 'לא נמצא בפח', 'products' ),
  14.     'parent_item_colon' => _x( 'עמודת אב', 'products' ),
  15.     'menu_name' => _x( 'מוצרים', 'products' ),
  16.     );
  17.     $args = array(
  18.     'labels' => $labels,
  19.     'hierarchical' => true,
  20.     'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields',),
  21.     'public' => true,
  22.     'show_ui' => true,
  23.     'show_in_menu' => true,
  24.     'menu_icon'    => 'dashicons-desktop',
  25.     'show_in_nav_menus' => true,
  26.     'publicly_queryable' => true,
  27.     'exclude_from_search' => false,
  28.     'has_archive' => true,
  29.     'query_var' => true,
  30.     'can_export' => true,
  31.     'rewrite' => true,
  32.     'capability_type' => 'post',
  33.     'taxonomies' => array('products_category'),
  34.     );
  35.     register_post_type( 'products', $args );
  36. }
  37.  
  38.  
  39. add_action( 'init', 'custom_taxonomy', 0 );
  40.  
  41. // Register Custom Taxonomy
  42. function custom_taxonomy() {
  43.  
  44.     $labels = array(
  45.         'name'                       => _x( 'קטגוריית מוצרים', 'Taxonomy General Name', 'text_domain' ),
  46.         'singular_name'              => _x( 'מוצר', 'Taxonomy Singular Name', 'text_domain' ),
  47.         'menu_name'                  => __( 'קטגוריית מוצרים', 'text_domain' ),
  48.         'all_items'                  => __( 'כל קטגוריות המוצרים', 'text_domain' ),
  49.         'parent_item'                => __( 'Parent Item', 'text_domain' ),
  50.         'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
  51.         'new_item_name'              => __( 'שם הקטגוריה החדשה', 'text_domain' ),
  52.         'add_new_item'               => __( 'הוסף קטגוריית מוצרים חדשה', 'text_domain' ),
  53.         'edit_item'                  => __( 'Edit Item', 'text_domain' ),
  54.         'update_item'                => __( 'Update Item', 'text_domain' ),
  55.         'view_item'                  => __( 'View Item', 'text_domain' ),
  56.         'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
  57.         'add_or_remove_items'        => __( 'Add or remove items', 'text_domain' ),
  58.         'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
  59.         'popular_items'              => __( 'Popular Items', 'text_domain' ),
  60.         'search_items'               => __( 'Search Items', 'text_domain' ),
  61.         'not_found'                  => __( 'Not Found', 'text_domain' ),
  62.         'no_terms'                   => __( 'No items', 'text_domain' ),
  63.         'items_list'                 => __( 'Items list', 'text_domain' ),
  64.         'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
  65.     );
  66.    
  67.    
  68.     $args = array(
  69.         'labels'                     => $labels,
  70.         'hierarchical'               => true,
  71.         'public'                     => true,
  72.         'show_ui'                    => true,
  73.         'show_admin_column'          => true,
  74.         'show_in_nav_menus'          => true,
  75.         'show_tagcloud'              => true,
  76.         'query_var'                   => true,
  77.         'rewrite'                   => array('slug' => 'products-categories'),
  78.     );
  79.     register_taxonomy( 'products_category',  'products' , $args );
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment