• I’ve found and included some code for enabeling tags for pages, and it works great.But I would also do the same with categories. I’m half way trough – I’ve enabeled the category box in admin mode, but I can’t manage pages to show when I select the category.

    Can anyone help? I would like to do this without a plugin…

    The code that works for tags on pages is this:

    // Make the metabox appear on the page editing screen
    function tags_for_pages() {
    	register_taxonomy_for_object_type('post_tag', 'page');
    }
    add_action('init', 'tags_for_pages');
    
    // When displaying a tag archive, also show pages
    function tags_archives($wp_query) {
    	if ( $wp_query->get('tag') )
    		$wp_query->set('post_type', 'any');
    }
    add_action('pre_get_posts', 'tags_archives');

    I found it here:

    I’ve added this code:
    register_taxonomy_for_object_type('category', 'page');

    But the part about making a category show both posts and pages is a mystry to me…

    Any code tip to share?

  • The topic ‘Enable categories for pages – by code’ is closed to new replies.