Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add custom fields to activity stream

  • Avatar of Nick
    Nick
    Participant

    @nhoover

    I’d like to add fields to the activity stream. I’m a relatively new coder so any help would be appreciated.

    I have studied this post and copied it to a tee but can’t seem to get it to work properly.

    http://buddypress.org/community/groups/creating-extending/forum/topic/adding-a-second-element-for-posting-with-an-activity/?topic_page=1&num=15

    What I am looking to do is to have 6 fields to every activity post: Post Title; Description; Make; Price; Model; and Location.

    I have added the fields to the form in the post-form.php as so.

    `


    @

     
    <input type="submit" name="aw-whats-new-submit" id="aw-whats-new-submit" value="” />

    `

    It looks great. Next I added this to my functions.

    `/**
    * This captures additional info at update.
    */
    function add_equipmentmeta_to_activity( $content, $user_id, $activity_id ) {
    bp_activity_update_meta( $activity_id, ‘equip’, ($_POST) );
    }

    add_action( ‘bp_activity_posted_update’, ‘add_equipmentmeta_to_activity’, 10, 3 );

    function my_equipmentmeta() {
    $my_equipmentmeta = bp_activity_get_meta( bp_get_activity_id(), ‘equip’ );
    //if (is_user_logged_in()) : {
    echo ‘(‘ . $my_equipmentmeta . ‘)‘;
    //}
    //endif;
    }
    add_action( ‘bp_activity_entry_meta’, ‘my_equipmentmeta’ );`

    Which was based on the previous post I mentioned above. I have been testing the ‘add_post_model’ to see if I could get just one to work.

    Lastly I changed the global.js like this.

    `/* Default POST values */
    var object = ”;
    var item_id = jq(“#whats-new-post-in”).val();
    var content = jq(“textarea#whats-new”).val();
    var title = jq(“input#add_post_title”).val();
    var make = jq(“input#add_post_make”).val();
    var model = jq(“input#add_post_model”).val();
    var price = jq(“input#add_post_price”).val();
    var location = jq(“input#add_post_location”).val();

    /* Set object for non-profile posts */
    if ( item_id > 0 ) {
    object = jq(“#whats-new-post-object”).val();
    }

    jq.post( ajaxurl, {
    action: ‘post_update’,
    ‘cookie': encodeURIComponent(document.cookie),
    ‘_wpnonce_post_update': jq(“input#_wpnonce_post_update”).val(),
    ‘content': content,
    ‘title': title,
    ‘make': make,
    ‘model': model,
    ‘price': price,
    ‘location': location,
    ‘object': object,
    ‘item_id': item_id
    },
    `

    I do not get any errors but I cannot get any data to show up. The holder for the meta tags shows up but it doesn’t contain any data. I’m not entirely sure where I am going wrong. Is this the best solution for my problem or is there something else I am missing?

    Thanks ahead of time for any help…

Viewing 11 replies - 1 through 11 (of 11 total)
  • Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Why the activity stream?

    Avatar of Nick
    Nick
    Participant

    @nhoover

    I’m open to any other thoughts.

    I’m after something like this on the homepage:

    http://www.nibydesigngroup.com/TUmailer/community.jpg

    I think it’s going to be some major code hacking unless someone has other thoughts.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    create your own BP component.

    http://codex.buddypress.org/extending-buddypress/creating-a-custom-buddypress-component

    Or you could use WP 3.0 custom post types and something like gravity forms.

    Avatar of Nick
    Nick
    Participant

    @nhoover

    I’m going to explore the custom post types and see where that leads. Thanks for the advice!!

    Avatar of Nick
    Nick
    Participant

    @nhoover

    I learned a lot about buddypress and wordpress custom fields today. Some thing I loved some things I didn’t. Still can’t seem to get it to function the way I would like. I can store the custom fields from the front end but I cannot display the fields in the activity stream with the post. It doesn’t seem to be possible yet.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    I think the activity stream only calls the excerpt. you’d have to have it call the meta on the blog posts

    Avatar of Nick
    Nick
    Participant

    @nhoover

    Latest attempts:

    If I type in:
    `function my_equipmeta() {
    $my_equipmeta = ‘joe';
    //if (is_user_logged_in()) : {
    echo ‘(‘ . $my_equipmeta . ‘)‘;
    //}
    //endif;
    }
    add_action( ‘bp_activity_entry_meta’, ‘my_equipmeta’ );`

    I can see the name ‘joe’ in the activity. That’s a good start

    If I input `$my_equipmeta = the_meta();`

    I see some custom field info but not all of the info displayed for each post is the meta stored with that post. IE some custom fields are showing up in posts that do not have that info stored. In other words it doesn’t appear to be working the way I need it to.

    Lastly:
    If I input:
    `$my_equipmeta = get_post_meta($post->ID, ‘Make’, true);`

    I receive nothing in return.

    I will keep tinkering but if anyone sees an error feel free to let me know. Thanks.

    Avatar of Nirok
    Nirok
    Participant

    @nirok

    This looks like a classifications listing website? Why not look at classipress? I don’t think buddypress activities would work in this case, even a simple wordpress loop might work better here… frontend editor isn’t available without some workaround and plugins but I think its coming in the next release of wordpress… classipress theme has a frontend editor

    Avatar of Nick
    Nick
    Participant

    @nhoover

    @Nirock Thanks for the advice. I think you are right on. After walking away from the code for a bit this weekend, I started to see the problem in a different light and came to the same conclusion. I’m not even sure the buddyPress software is really needed for this project. It may be overkill for my client. Hopefully at some point adding custom fields to the activity stream will become simpler for hacks like me. I really appreciate all the help I got on this.

    Avatar of Artform
    Artform
    Participant

    @a3sthetix

    I realize it’s been almost 2 years since this topic began, but I’m working on a similar issue.

    My solution is to encode the tags / meta information into shortcodes which are appended to the post. When the post is displayed, the short codes are interpreted and displayed.

    Avatar of thisisnousername
    thisisnousername
    Participant

    @thisisnousername

    @a3sthetix did you get it working?

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

You must be logged in to reply to this topic.