BuddyDev

Search

[Resolved] Displaying Categories for Custom Post Types

  • Participant
    Level: Initiated
    Posts: 10
    Brendan on #14769

    Hello,

    Thanks for all the help so far.

    I have another problem.

    When setting up a form for a custom post type, the line
    allowed_categories' => get_all_category_ids(),

    Doesn’t show any UI/check boxes for the user to select categories for their custom post type post.

    Any ideas? Thanks!

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #14788

    Hi Brendan,
    For custom taxonomy you will need to have the ids from that taxonomy. The solution is to use

    get_terms with taxonomy and fields=>’ids’ in the arguements.

    
    https://developer.wordpress.org/reference/functions/get_terms/
    

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Brendan on #14863

    I’m not sure what you mean. When I register the custom post types, they share categories and tags with normal blog posts. should it not just work?

    Can you give me an example of what to add to the form setup that would allow categories and tags for the post type ‘community-story’ (slug)

    Being able to exclude certain categories from the front end post would be nice as well.

    I think I can take it from there.

  • Participant
    Level: Initiated
    Posts: 10
    Brendan on #15009

    Hello, thank you for all of your help so far, but I’m not sure how/where to implement your suggestion.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #15034

    Hi Brendan,
    Please allow me till tomorrow to post the code.

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 10
    Brendan on #15412

    Hey sir, thanks for being so great as to help. Do you have the code that I need to make this work? Thanks!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #15431

    Hello Brendan,

    Please check the following example code. it might help you.

    
    /**
     * Register a custom Form
     *
     */
    function my_post_form() {
    
    	$settings = array(
    		'post_type'             => 'book', // Replace it with your custom post type.
    		// Which post type.
    		'post_author'           => bp_loggedin_user_id(),
    		// Who will be the author of the submitted post.
    		'post_status'           => 'publish',
    		// How the post should be saved, change it to 'publish' if you want to make the post published automatically.
    		'current_user_can_post' => is_user_logged_in(),
    		// Who can post.
    		'show_categories'       => true,
    		// Whether to show categories list or not, make sure to keep it true.
    		'tax' => array(
    			'category' => array(
    				'taxonomy'  => 'category',
    				'view_type' => 'checkbox',
    				'include' => array( 1, 31 ), // Replace categories ids you want to show.
    			),
    		),
    	);
    
    	bp_new_simple_blog_post_form( 'my form', $settings );
    }
    
    add_action( 'bp_init', 'my_post_form', 4 );
    

    Thank You
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved