Skip to:
Content
Pages
Categories
Search
Top
Bottom

Make Custom post type a parent of forum


  • tonipetrov91
    Participant

    @tonipetrov91

    I’m trying to add a parent/child relationship between bbpress forums and a custom post type I’ve created. Is there a way to do that, currently I can only make forum a child of another forum?

    I’ve tried adding a custom meta box that would allow that:

    
    function my_add_meta_boxes() {
    	add_meta_box( 'lesson-parent', 'Module', 'lessons_attributes_meta_box', 'forum', 'side', 'high' );
    }
    add_action( 'add_meta_boxes', 'my_add_meta_boxes' );
    function lessons_attributes_meta_box( $post ) {
    	$post_type_object = get_post_type_object( $post->post_type );
    	$pages = wp_dropdown_pages( array( 'post_type' => 'lesson', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __( '(no parent)' ), 'sort_column'=> 'menu_order, post_title', 'echo' => 0 ) );
    	if ( ! empty( $pages ) ) {
    		echo $pages;
    	}
    }
    

    This shows the metabox and I can select the CPTs from a dropdown list, they are not saved. This should be because the forum post type has hierarchy=>true. So I’ve tried to disable it using the below code, but it doesn’t work:

    
    add_action('registered_post_type', 'disable_hierarchical', 10, 2 );
    
    // Runs after each post type is registered
    function disable_hierarchical($post_type, $pto){
    
        // Return, if not post type posts
        if ($post_type != 'forum') return;
    
        // access $wp_post_types global variable
        global $wp_post_types;
        $wp_post_types['forum']->hierarchical = false;
    }
    

    The above code works fine with the page post type, but not with the forum. What’s special about it that I’m missing?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar