The following code will add the categories selector widget to the WordPress Page editor interface…
add_action('admin_menu', 'my_post_categories_meta_box');
function my_post_categories_meta_box() {
add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'page', 'side', 'core');
}
What I would like to do is to figure out how to modify the resulting category listing so that it only contains a predefined list of hard coded categories that I define.
Since I’m adding this via my custom theme, it will only appear on the page editor when my theme is active on the site. And I have some specific “handler” categories that my theme installs into the site and later uses to determine layout elements. I only want these specific categories to be listed in this particular instance of the categories widget.
Use a modified version of
post_categories_meta_box
, in which you change the call towp_category_checklist
to a modified version,wp_category_checklist_modified
.post_categories_meta_box_modified:
I’ve only change the line of the original function
to
wp_category_checklist_modified:
Here I’ve added an extra argument to
wp_category_checklist_modified
,$include_cats
, in which you can specify the categories ids, then I use this list in the two calls toget_categories
passing it as theinclude
parameter.These functions are not documented (as much as I am be able to find), so I’ve had to take a look to the source code.
Then you will simply use
Hope this helps.