Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to assign the same taxonomy to topics as the parent forum?

  • @themichaelglenn

    Participant

    I’m looking for a way to automatically assign a forum’s custom taxonomy to all of that forum’s topics.

    I recently registered a custom taxonomy that I want to share across all pages, posts, forums and topics, and since I create most of the content on my site, assigning the right taxonomy to pages, posts, and forums is easy. But I’d rather not have to manually assign taxonomy to topics, especially since any of my members can create a new topic at any time.

    Is there a way to tell WP to get the taxonomy for the parent forum, and automatically save all topics in that forum with the exact same taxonomy?

    (If it helps, this is the code I used to register a custom taxonomy to be used on all pages, posts, forums and topics):

    // Add custom taxonomy
    function postcats_init() {
    	// create a new taxonomy
    	register_taxonomy(
    		'game-categories',
    		array('post','page','forum','topic'),
    		array(
    			'label' => __( 'Games' ),
    			'rewrite' => array( 'slug' => 'game-posts' ),
        'hierarchical'      => true,
        'capabilities' => array(
    				'assign_terms' => 'edit_pages',
    				'edit_terms' => 'manage_categories',
        		'assign_terms' => 'edit_pages'
    			)
    		)
    	);
    }
    
    add_action( 'init', 'postcats_init' );
  • You must be logged in to reply to this topic.
Skip to toolbar