• Hi,
    I need help with something i really have tried to solve on my own.

    I would like to have a link/button on each of the topics (only the first one under each topic) in bbPress forum. This link should go to “Create New Post” page where the user can generate a new wp post in a specific category. I have same categories for forum topics and posts. Therefore category for the new post should be the same as for the forum topic ($kat_id in the following)

    I have this until now, but i dont know how to use $kat_id to get same category for the blog post. I need to assign this $kat_id to the category for the blog post, but how ??

    function add_content_before_first_reply_content($content,$id){
    
    	$post = get_post($id);
    	$topic_id = bbp_get_topic_id();
    	$reply_id = bbp_get_reply_id();
    	
    	$hf_user = wp_get_current_user();
    	$hf_username = $hf_user->user_login;
    	
        $kat_id = wp_get_post_parent_id($post);
    	
    	
        <code>$content_to_add =&quot;<a href=&quot;create-new-post?vis=$kat_id&quot;>&nbsp;Add new blog &nbsp;</a>&quot;;</code>
    	
    	if ($topic_id === $reply_id) {
    		// do whatever you need to in  here
    		$content .= $content_to_add;
    	}
    
    	return $content;
    
    }
    add_filter( 'bbp_get_reply_content', 'add_content_before_first_reply_content', 99, 2 ); 

    Thanks in advance !!

    • This topic was modified 4 years, 2 months ago by michaelgoal.
    • This topic was modified 4 years, 2 months ago by michaelgoal.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator James Huff

    (@macmanx)

    I recommend asking at https://bbpress.org/forums/ so the bbPress developers and support community can help you with this.

    Thread Starter michaelgoal

    (@michaelgoal)

    Yes i asked in that forum too but they said that i could ask here ??
    Its a wp question.
    Its about the wp Blog, how i can assign the $kat_id (in the URL) to the Blog post when creating a new blog post.
    Hope i can get help here.

    Moderator bcworkz

    (@bcworkz)

    It sounds like you’ve been bounced around. Our apologies. I think you want a certain category pre-selected when a user is taken to the post edit screen, correct? You can use the “wp_terms_checklist_args” filter to set the “selected_cats” arg with an array of term IDs that should be selected.

    The problem is this filter applies to all calls to wp_terms_checklist(). You only want the selection to be used in this one context. Try including the category ID as one of the URL parameters in the link. Use a unique key name unlikely to conflict with anything else. Your filter callback can check for this parameter in $_GET. If it exists, set the “selected_cats” arg, otherwise return the args array unchanged.

    Sometimes WP will strip out unrecognized URL parameters. I’m not sure if this is the case here or not. The easiest way to know is to just try it and see.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create new WP post from a forum topic’ is closed to new replies.