Skip to content

Changing Post Type and Taxonomy Parameters

Matthew Boynes edited this page Sep 24, 2013 · 2 revisions

There are many ways to change the arguments passed to register_post_type and register_taxonomy using SuperCPT. In each case, see the respective Codex pages for the parameters and values you can pass.

Pass arguments in the object instantiation

The 4th parameter in Super_Custom_Post_Type, and the 5th parameter in Super_Custom_Taxonomy are arrays used to override the default parameters. For instance:

$movies = new Super_Custom_Post_Type( 'movie', 'Movie', 'Movies', array( 'has_archive' => false ) );
$actors = new Super_Custom_Taxonomy( 'actor', 'Actor', 'Actors', 'tag', array( 'show_admin_column' => true ) );

Magic methods

As of 0.1.3

After instantiating the object, you can modify the parameters directly on the objects via magic methods. That is to say, each parameter has a method on the object. Calling the method without any arguments returns the value, and calling it with arguments sets the value. Passing multiple arguments assumes a numerically indexed array. For instance:

$movies = new Super_Custom_Post_Type( 'movie' );
$movies->has_archive( false );
$movies->supports( 'title', 'editor' )
# That could have also been written as $movies->supports( array( 'title', 'editor' ) );
$actors = new Super_Custom_Taxonomy( 'actor' );
$actors->show_admin_column( true );

Modify the class properties

The parameters passed to the core functions are stored in the class properties cpt and args for custom post types and taxonomies respectively. These are publicly-accessible arrays, and you can modify them as you see fit. For instance:

$movies = new Super_Custom_Post_Type( 'movie' );
$movies->cpt['has_archive'] = false;
$actors = new Super_Custom_Taxonomy( 'actor' );
$actors->args['show_admin_column'] = true;

Filters

If you're going to be registering a number of similar post types and/or taxonomies, you can modify them in bulk using scpt_plugin_default_cpt_options and scpt_plugin_default_tax_options. Note that this will only override the defaults; anything passed through object instantiation will take precedence. For instance:

function my_cpt_defaults( $args, $post_type ) {
	$args['has_archive'] = false;
	return $args;
}
add_filter( 'scpt_plugin_default_cpt_options', 'my_cpt_defaults', 10, 2 );

function my_tax_defaults( $args, $taxonomy ) {
	$args['show_admin_column'] = true;
	return $args;
}
add_filter( 'scpt_plugin_default_tax_options', 'my_tax_defaults', 10, 2 );
You can’t perform that action at this time.