Skip to:
Content
Pages
Categories
Search
Top
Bottom

wp_insert_post(), Creating a sticky topic with forum parent parent.

  • @leoclipartillustrationcom

    Participant

    I’m writing a theme function which automatically creates a discussion forum for a post on publish. I can create a forum and a topic, but linking the two has proven difficult. Here is what I have:

    $forum_topic = array(
    
    'post_title' => $post->post_title . ' - test. ',
    
    'post_content' => $post->post_title . ' test',
    
    'post_name' => $post->post_title . 'test',
    
    'post_status' => 'publish',
    
    'post_parent' => $created_forum_id,
    
    'post_type' => 'topic',
    
    );
    
    $posted_topic_id = wp_insert_post($forum_topic);
    

    Then, making it sticky, this is what I’ve attempted:

    `update_post_meta( $created_forum_id, ‘_bbp_sticky_topics’, array($posted_topic_id) );`

    Both the forum and topic are created, but the parent and sticky are not assigned. How can I do this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @johnjamesjacoby

    Keymaster

    Try bbp_insert_topic(), bbp_insert_forum(), and bbp_stick_topic()

    @leoclipartillustrationcom

    Participant

    Great, will do! Then when I do update_post_meta it should work as expected? or are there any other details? I appreciate the answer.

    @leoclipartillustrationcom

    Participant

    Nevermind – I missed your “stick_topic” suggestion. Thanks.

    @downloadtaky

    Participant

    Hi, actually I’m trying to develop a WP plugin that will do almost the same thing you were trying to do.
    But, my lack of knowledge and the lack of documentation (I can’t find it!) aren’t helping me very much.
    This is what I have actually:
    https://github.com/maisdesign/MDPostEforumsCreator

    As you can see in my index.php file that is here:

    <?php
    /*
    Plugin Name: Post And Forum Creator by MaisDesign & Stestaz
    Plugin URI: http://maisdesign.it
    Description: You give it a title and it automatically create a blank post and forum with that title, that's it!
    Version: 1.0.0
    Author: MaisDesign & Stestaz
    Author URI: http://maisdesign.it
    License: 
    License URI: 
    */
    /* Documentazione:
    	Quello che sto cercando di ottenere è di svolgere tutto in una sola pagina, sono certo che non serva richiamare BBHOST e compagnia bella per inserire un cavolo di articolo ma sono le 2.20 AM e non so più che pesci pigliare!
    	In fondo a questa pagina troverai del codice commentato, se ci sono bestemmie nei commenti lasciale dove stanno, sono di buon auspicio :-P
    */
    /* Definiamo la versione */
    
    if (!defined('MD_POSTFORUM_CREATOR_VERSION_KEY'))
        define('MD_POSTFORUM_CREATOR_VERSION_KEY', 'md_postforum_creator_version');
    
    if (!defined('MD_POSTFORUM_CREATOR_VERSION_NUM'))
        define('MD_POSTFORUM_CREATOR_VERSION_NUM', '1.0.0');
    
    add_option(MD_POSTFORUM_CREATOR_VERSION_KEY, MD_POSTFORUM_CREATOR_VERSION_NUM);
    
    /*
        * This example will work at least on WordPress 2.6.3, 
        * but maybe on older versions too.
        */
       add_action( 'admin_init', 'md_postforum_creator_init' );
       add_action( 'admin_menu', 'md_postforum_creator_menu' );
       
       function md_postforum_creator_init() {
           /* Register our stylesheet. */
           wp_register_style( 'mdPostforumCreatorStyle', plugins_url('css/mdpostforumstyle.css', __FILE__) );
    	       wp_register_script( 'mdPostforumCreatorScript', plugins_url( '/js/alajax-1.2.js', __FILE__ ) );
       };   
       function md_postforum_creator_menu() {
           /* Register our plugin page */
           $page = add_submenu_page( 'options.php', 
                                     __( 'MDPFC Plugin', 'md-postforum-creator' ), 
                                     __( 'MDPFC Plugin', 'md-postforum-creator' ),
                                     'administrator',
                                     __FILE__, 
                                     'md_postforum_creator_manage_menu' );
      
           /* Using registered $page handle to hook stylesheet loading */
           add_action( 'admin_print_styles-' . $page, 'md_postforum_creator_styles' );
    		add_action('admin_print_scripts-' . $page, 'md_postforum_creator_scripts');
       };   
       function md_postforum_creator_styles() {
           /*
            * It will be called only on your plugin admin page, enqueue our stylesheet here
            */
           wp_enqueue_style( 'mdPostforumCreatorStyle' );
       };
       function md_postforum_creator_scripts() {
            /* Link our already registered script to a page */
            wp_enqueue_script( 'mdPostforumCreatorScript' );
        };
       /*function md_postforum_creator_manage_menu() {
       };*/
       add_action('admin_menu', 'register_md_postforum_creator_menu');
    function register_md_postforum_creator_menu() {
       add_menu_page( 'MDPFC Options', // $page_title
                      'MDPFC Options', // $menu_title
                      'manage_options', // $capability
                      'md-postforum-creator-menu-page-slug', // $menu_slug
                      'md_postforum_creator_menu_page', // $function
                      plugins_url( 'md-postforum-creator/images/mdpostforum.png' ), /* $icon_url*/
                      3 ); /* $position*/
    };
    
    function md_postforum_creator_menu_page() {
       /* Does the user have the right permissions?*/
       if (!current_user_can('manage_options')) {
          wp_die( 'Sorry, you do not have permission to access this page.');
       };
      if(isset($_POST['new_post']) == '1') {
        $post_title = $_POST['post_title'];
        $post_category = $_POST['cat'];
        $post_content = $_POST['post_content'];
    
        $new_post = array(
              'ID' => '',
              'post_author' => $user->ID, 
              'post_category' => array($post_category),
              'post_content' => '', 
              'post_title' => wp_strip_all_tags($post_title),
              'post_status' => 'draft'
            );
    
        $post_id = wp_insert_post($new_post);
    };          
    echo '
    <form action="'.admin_url('admin.php?page=md-postforum-creator-menu-page-slug').'" method="post">
        <input type="text" name="post_title" size="45" id="input-title"/>
        <input type="hidden" name="new_post" value="1"/>';
    	wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1&hierarchical=1');
        echo '<input class="subput round" type="submit" name="submit" value="Post"/>
    </form>';
    };?>

    My plugin is almost complete, what I can’t understand is How to create also a forum with same title of the post created by the form.

    Is there anyone who can send me to the right direction? Thank you.

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