Last active
March 12, 2019 15:22
-
-
Save darioielardi/2f93ae83fa3e3159b1cddf40874d968b to your computer and use it in GitHub Desktop.
[WP CPT + Taxonomy + Meta Boxes] Example Wordpress Custom Post Type with Taxonomy and Meta Boxes #wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sedi Custom Post Type | |
class Sedi_Cpt { | |
public function __construct() | |
{ | |
add_action( 'init', array( $this, 'build_custom_post_type' ), 0 ); | |
add_action( 'init', array( $this, 'build_aree_taxonomy' ), 0 ); | |
add_action( "add_meta_boxes", array( $this, "build_meta_boxes" ) ); | |
} | |
function build_custom_post_type() { | |
$labels = array( | |
'singular_name' => 'Sede', | |
'menu_name' => 'Sedi', | |
'all_items' => 'Tutte le Sedi', | |
'add_new_item' => 'Aggiungi Nuova Sede', | |
'add_new' => 'Aggiungi Sede', | |
'new_item' => 'Nuova Sede', | |
'edit_item' => 'Modifica Sede', | |
'view_item' => 'Vedi Sede', | |
'search_items' => 'Cerca Sede', | |
'not_found' => 'Sedi non trovate', | |
'not_found_in_trash' => 'Sedi non trovate nel cestino', | |
); | |
$args = array( | |
'label' => 'Sedi', | |
'description' => 'Sedi', | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'), | |
'public' => true, | |
'hierarchical' => false, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'has_archive' => true, | |
'can_export' => true, | |
'exclude_from_search' => false, | |
'yarpp_support' => true, | |
'taxonomies' => array('aree'), | |
'publicly_queryable' => true, | |
'capability_type' => 'page' | |
); | |
register_post_type( 'sedi', $args ); | |
} | |
function build_aree_taxonomy() | |
{ | |
$labels = array( | |
'name' => 'Aree', | |
'singular_name' => 'Aree', | |
'search_items' => 'Cerca Area', | |
'all_items' => 'Tutte le Aree', | |
'edit_item' => 'Modifica Area', | |
'update_item' => 'Aggiorna Area', | |
'add_new_item' => 'Aggiungi Nuova Area', | |
'new_item_name' => 'Nome Nuova Area', | |
'menu_name' => 'Aree', | |
); | |
register_taxonomy('aree', array('sedi'), array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'area' ), | |
)); | |
} | |
function town_meta_box_markup() | |
{ | |
} | |
function region_meta_box_markup() | |
{ | |
} | |
function build_meta_boxes() | |
{ | |
add_meta_box('region-meta-box', 'Regione', 'regione_meta_box_markup', 'sedi', 'side', 'low', null); | |
add_meta_box("town-meta-box", "Città", "town_meta_box_markup", "sedi", "side", "low", null); | |
} | |
} | |
new Sedi_Cpt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment