-
-
Save matfish2/3861692 to your computer and use it in GitHub Desktop.
WP: Custom Post Types and Custom Taxonomies
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 | |
// ***** Declare function that buids the post type | |
function add_post_type($name, $args = array() ) { | |
add_action('init',function() use($name, $args) { | |
// make post type name capitalized | |
$upper = ucwords($name); | |
// make name acceptable | |
$name = strtolower(str_replace(' ', '_', $name)); | |
// merge default args with passed args | |
$args = array_merge( | |
array( | |
'public' => true, | |
'label' => ucwords("$name" . 's'), | |
'labels' => array( | |
'add_new_item' => "Add New $upper" . ''), | |
'supports' => array( | |
'title','editor','excerpt'), | |
'taxonomies' => array('category') | |
),$args); | |
// build post type | |
register_post_type($name, $args ); | |
}); | |
}; | |
// ***** Declare function that builds the taxonomy | |
function add_taxonomy($name, $post_type, $args = array()) { | |
add_action('init', function() use($name, $post_type, $args) { | |
// make taxonomy name capitalized | |
$upper = ucwords($name); | |
$plural = ucwords("$name" . 's'); | |
// make name acceptable | |
$name = strtolower(str_replace(' ', '_', $name)); | |
// merge default args with passed args | |
$args = array_merge(array( | |
'label' => $plural, | |
),$args); | |
register_taxonomy($name, $post_type, $args); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment