Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dmje/b7d816232494eeb5ad63595b1438fbec to your computer and use it in GitHub Desktop.

Select an option

Save dmje/b7d816232494eeb5ad63595b1438fbec to your computer and use it in GitHub Desktop.
Was using on WPClientPro but no longer
<?php
// Add taxonomy to the Space Content CPT and populate with initial values
if ( ! taxonomy_exists( 'space-content-type' ) ) {
// Define your taxonomy labels
$labels = array(
'name' => _x( 'Content Types', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Content Type', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Content Types', 'textdomain' ),
'all_items' => __( 'All Content Types', 'textdomain' ),
'parent_item' => __( 'Parent Content Type', 'textdomain' ),
'parent_item_colon' => __( 'Parent Content Type:', 'textdomain' ),
'edit_item' => __( 'Edit Content Type', 'textdomain' ),
'update_item' => __( 'Update Content Type', 'textdomain' ),
'add_new_item' => __( 'Add New Content Type', 'textdomain' ),
'new_item_name' => __( 'New Content Type Name', 'textdomain' ),
'menu_name' => __( 'Content Types', 'textdomain' ),
);
// Define your taxonomy arguments
$args = array(
'labels' => $labels,
'public' => true,
'hierarchical' => true, // Change this to false if it's not hierarchical
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'space-content-type' ), // Change this to your desired slug
);
// Register the taxonomy and associate it with the custom post type
register_taxonomy( 'space-content-type', array( 'wpcp_space_content' ), $args );
// Add default terms
$default_terms = array(
'Notebook',
'Link',
);
foreach ($default_terms as $term) {
wp_insert_term( $term, 'space-content-type' );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment