Skip to:
Content
Pages
Categories
Search
Top
Bottom

Inserted Topic Has No Content


  • Marigold
    Participant

    @marigoldcoop

    I have written a function to insert a post into a private member forum, but when I click on the topic it says it is empty?

    $post_parent = 0;
    $forum_id = 5485; // Membership Forum 5485

    $topic_data = array(
    //’post_parent’ => $post_parent,
    ‘post_author’ => 1,
    ‘post_title’ => $output_title,
    ‘post_content’ => “<div class=’application-form’>$output_content</div>”,
    ‘comment_status’ => ‘closed’,
    ‘menu_order’ => 0
    );

    $topic_meta = array(
    ‘forum_id’ => $forum_id
    );

    $topic_id = bbp_insert_topic( $topic_data, $topic_meta );
    bbp_stick_topic($topic_id , false);

    WP v5.5.1
    BBP v2.6.5
    BP v6.3.0

Viewing 5 replies - 1 through 5 (of 5 total)

  • Robin W
    Moderator

    @robin-w

    your content is the contents of the variable $output_content which is not defined in the code above, so the function would either fail and do nothing or make contents empty


    Marigold
    Participant

    @marigoldcoop

    Sorry, this is a simplification, it is indeed defined above this block, but even if I give it a content value of ‘Test’ I still get “Oh, bother! No topics were found here.”


    Robin W
    Moderator

    @robin-w

    suspect post status and post parent (which you have commented out) might be the issue

    'post_status' => bbp_get_public_status_id(),

    and post parent should be the forum it belongs to, so $forum_id in your code

    'post_parent' => $forum_id,


    Marigold
    Participant

    @marigoldcoop

    Yes! thank you. That did the trick.

    I was under the impression that as it was a new topic it would be set to 0, and the forum id would be set in the meta args.


    Robin W
    Moderator

    @robin-w

    it needs both !

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