I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
I would like to display the full list of categories on the Page creation page, so that the user can pick using checkboxes which category posts should appear on that page.
I then need to retrieve the chosen categories for that specific page in my custom page templates, so that I can modify my loop to filter for only those chosen categories.
By default page post type doesn't support category taxonomy. But you can easily fix it by register category taxonomy for page post type:
add_action( 'init', 'wpse8170_init' );
function wpse8170_init() {
register_taxonomy_for_object_type( 'category', 'page' );
}
Now you will see categories meta box in the same place as you see it at post creation page.
To get page's categories just call wp_get_post_categories
function like this (thanks to @Subharanjan):
$page_categories = wp_get_post_categories( get_the_ID() );
$page_categories = wp_get_post_categories( get_the_ID() );
Pass the current page id/ any pageid as the param and get the asociated categories.