0

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.

where I would like to display it

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.

2

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() ); 
  • How beautifully simple! how would I retrieve the chosen categories on their respective pages? – Kayo Feb 7 '13 at 11:00
  • to be clear, I already have the code to loop through a selection of categories, I just need to retrieve the list of chosen categories to use as arguments in my existing loop. – Kayo Feb 7 '13 at 11:01
  • @Kayo updated my answer – Eugene Manuilov Feb 7 '13 at 11:26
2
$page_categories = wp_get_post_categories( get_the_ID() ); 

Pass the current page id/ any pageid as the param and get the asociated categories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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