Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom Fields


  • Clivesmith
    Participant

    @clivesmith

    On my site I am the only one that can create a new topic (anyone can reply) I am trying to introduce a couple of pieces of text that will be added to the end of the content of each reply. (they are twitter names and twitter hashtags).

    I have found this piece of code that allows me to add some input fields to a new topic but it only works at the front end, I have been trying with no luck to find a hook I can use to get this to work on the back end. Can any one help please ?

    add_action ( ‘bbp_theme_before_topic_form_content’, ‘bbp_extra_fields’);
    function bbp_extra_fields() {
    $value = get_post_meta( bbp_get_topic_id(), ‘bbp_extra_field1’, true);
    echo ‘<label for=”bbp_extra_field1″>hashtag</label><br>’;
    echo “<input type=’text’ name=’bbp_extra_field1′ value='”.$value.”<br>’>”;
    $value = get_post_meta( bbp_get_topic_id(), ‘bbp_extra_field2’, true);
    echo ‘<br><label for=”bbp_extra_field2″>Twitter Name</label><br>’;
    echo “<input type=’text’ name=’bbp_extra_field2′ value='”.$value.”‘>”;
    }
    /* Write out to meta table */
    add_action ( ‘bbp_new_topic’, ‘bbp_save_extra_fields’, 10, 1 );
    add_action ( ‘bbp_edit_topic’, ‘bbp_save_extra_fields’, 10, 1 );
    $topic_id = bbp_get_topic_id();
    function bbp_save_extra_fields($topic_id) {
    if (isset($_POST) && $_POST[‘bbp_extra_field1’]!=”)
    update_post_meta( $topic_id, ‘bbp_extra_field1’, $_POST[‘bbp_extra_field1’] );
    if (isset($_POST) && $_POST[‘bbp_extra_field2’]!=”)
    update_post_meta( $topic_id, ‘bbp_extra_field2’, $_POST[‘bbp_extra_field2’] );
    }

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

  • Robin W
    Moderator

    @robin-w

    are these tags the same for every reply?


    Clivesmith
    Participant

    @clivesmith

    no, the hashtag will be any one of about ten but the other one will be unique for each topic.


    Robin W
    Moderator

    @robin-w

    ok, you’d do it with a metabox in the backend topic and reply custom post types

    this should get you started

    Creating Custom Post Meta Boxes in WordPress


    Clivesmith
    Participant

    @clivesmith

    Great, thanks Robin


    Clivesmith
    Participant

    @clivesmith

    The custom post meta boxes creates the boxes in a post, I still cannot find a hook to create them in the “new Topic” back end.
    Thanks


    Robin W
    Moderator

    @robin-w

    you need to alter ‘post’ to topic and reply eg (untested)

    function adding_custom_meta_boxes( $post_type, $post ) {
        add_meta_box( 
            'my-meta-box',
            __( 'My Meta Box' ),
            'render_my_meta_box',
            'topic',
            'normal',
            'default'
        );
    add_meta_box( 
            'my-meta-box2',
            __( 'My Meta Box 2' ),
            'render_my_meta_box',
            'reply',
            'normal',
            'default'
        );
    
    }
    add_action( 'add_meta_boxes', 'adding_custom_meta_boxes', 10, 2 );

    Clivesmith
    Participant

    @clivesmith

    Hi,
    I think that “custom post meta boxes” is more complicated than I need, it creates a new menu on the dashboard and I have to include what I want there, as I will use unique labels on each new topic I think it goes too far. I can see the fields I want with the code above on the front end ‘new topic’, I just want the code to show up in the backend “create new topic” if there is no way to include them in the backend ‘New Topic’ I will accept that.

    I then need to include these fields at the end of the content before posting both in the topic and the replies — content = content + bbp_extra_field1 + bbp_extra_field2 do you know where I can get at the content before it is written to the table.

    Thanks


    Robin W
    Moderator

    @robin-w

    it shouldn’t create a new menu on the dashboard, just a new item in topic.

    If you’d like specific help with your forum (beyond free help) contact me via

    http://www.rewweb.co.uk


    Clivesmith
    Participant

    @clivesmith

    Hi Robin,
    Thanks for the offer, but my site is for public information and I don’t make enough to pay for the hosting.

    I think I just need to find the parameters for the hook bbp_theme_before_topic_form_submit_button so I can add the contents of the field to the end of the topic contents.

    Thanks for your help

    Regards
    Clive


    Robin W
    Moderator

    @robin-w

    sorry – I’m just a volunteer, only so much I can do for free


    Clivesmith
    Participant

    @clivesmith

    That’s fine, I really appreciate the help you have given me, I am trying to learn as quick as I can.

    Thanks for all you help

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