2

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:

$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.

1
  • I suppose the big question is, should register_post_type be accepting custom parameters. If that's not intended behaviour for the function, i'd expect your code to stop working in future(but that may not be the case). I guess the only way to know for sure would be to backtrace that function's history and see if the function is intended to support custom args.
    – t31os
    Commented Apr 18, 2011 at 11:50

1 Answer 1

2

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.

1
  • I see what you mean, and will be looking into updating my project to follow this safeguard. It would definitely not be good if I lost the current ability to add arguments. Commented Apr 18, 2011 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.