Is it a good practice to include custom options when registering a post type?

More of an open discussion than a question, really, because I know adding custom arguments to the post type object does work, but I’m wondering if it is technically wrong in any way.

Basically, when registering a post type:

Read More
$labels = array(
    'name' => _x('Drews', 'post type general name'),
    'singular_name' => _x('Drew', 'post type singular name'),
    'add_new' => __('Add New'),
    'add_new_item' => __('Add New Item'),
    'edit_item' => __('Edit Item'),
    'new_item' => __('New Item'),
    'view_item' => __('View Item'),
    'search_items' => __('Search Items'),
    'not_found' =>  __('No Items found'),
    'not_found_in_trash' => __('No Items found in Trash'), 
    'menu_name' => 'Archives'
);
$rewrite = array(
    'slug' => 'drews'
);
$args = array(
    'labels' => $labels,
    'public' => true,
    'show_in_menu' => true, 
    'query_var' => 'drews',
    'rewrite' => $rewrite,
    'has_archive' => true, 
    'hierarchical' => false,
    'supports' => array('title','editor','author','comments'),
    '_drew_made_this' => true
); 
register_post_type('drews',$args);

Make note of the very last line in my $args array, ‘_drew_made_this’ set to ‘true’. This allows me to condition against this in several useful ways, sort of how you would filter against ‘_builtin’ when using get_post_types(). Like I said, I know this works because I’m using it, but is there any potential for this to break WordPress in any weird way.

Related posts

Leave a Reply

1 comment

  1. You can add as many arguments as you want to the register_post_type() $args as they are all save in $wp_post_types global in an array (ex: $wp_post_types[type] = $args), but i’m not sure if that is the best way to go since this could easily be changed in the future and then your functions will break, a better way to go would be to create your own option in the options table and use that, what i mean is that you could use get_post_types() and save them as an array in a type => $args manner and that way you are not depending on the core functionality to stay in the current state. Hope this makes scene.