Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
thanks for the edit bungeshea –  Kayo Feb 7 '13 at 10:00

2 Answers 2

up vote 2 down vote accepted

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() ); 
share|improve this answer
    
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
$page_categories = wp_get_post_categories( get_the_ID() ); 

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

share|improve this answer
    
thank you, just what I needed –  Kayo Feb 7 '13 at 11:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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