Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbPress and custom fields


  • pandreas
    Participant

    @pandreas

    Is there an easy way to add custom fields to the front-end of bbpress?

    I am using some custom fields (file, image attachments) with the help of this plugin https://wordpress.org/plugins/advanced-custom-fields/ so I add them to support bbpress forums and topics as well.

    But these custom fields are available only to back-end of topics and forums and not to the front-end.

    How can this change?

    Thank you in advanced!

    Andreas

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

  • Robkk
    Moderator

    @robkk


    PinkishHue
    Participant

    @pinkishhue

    I was able to do this by adding this to my functions.php / custom plugin:

    
    // Add custom fields to bbpress topics on front end
    add_action ( 'bbp_theme_before_topic_form_content', 'bbp_extra_fields');
    function bbp_extra_fields() {
       $value = get_post_meta( bbp_get_topic_id(), 'YOUR-FIELD-NAME', true);
       echo '<label for="bbp_extra_field">My Extra Field:</label><br>';
       echo "<input type='text' name='YOUR-FIELD-NAME' value='".$value."'>";
    }
    
    //Save and update the values from the front end
    add_action ( 'bbp_new_topic', 'bbp_save_extra_fields', 10, 1 );
    add_action ( 'bbp_edit_topic', 'bbp_save_extra_fields', 10, 1 );
    
    function bbp_save_extra_fields($topic_id=0) {
      if (isset($_POST) && $_POST['YOUR-FIELD-NAME']!='')
        update_post_meta( $topic_id, 'YOUR-FIELD-NAME', $_POST['YOUR-FIELD-NAME'] );
        
    }
    

    I think that’s correct but am in a bit of a code-haze at the moment! Hopefully it puts you on the right track at least. (And I can’t remember where I got the original code so apologies for not crediting original author)


    balotuixach
    Participant

    @balotuixach

    Thank Pinkishhue for help!


    pandreas
    Participant

    @pandreas

    Thank you all for your replies.

    I have found this solution https://wordpress.org/plugins/gd-bbpress-attachments/screenshots/ which works perfectly!!

    Regards,

    Andreas

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