Forums

[closed] Using a buddypress xprofile field as a custom field in post (4 posts)

  1. grezza
    Member
    Posted 1 year ago #

    Hi,

    Im trying to add a buddypress profile field (set of checkboxes) to also be available option with which to tag a post. Meaning that a buddypress user and a post can be linked by common data. In simple terms, one set of checkboxes accessible and assignable to both users and posts.

    Anybody know how to do this?

    Thanks for your help.

  2. shawnyuan
    Member
    Posted 1 year ago #

    Start with this:

    Go to your buddypress plugin directory and find this:

    buddypress/bp-themes/bp-default/registration/register.php.

    After, study the code below. It allows you to get details for the logged in user. The code below assumes that you have the following profile fields: First Name, Last Name, Location and Website.

    [Code moderated]

    The key is the line below, which allows you to match the profile field you are looking for <?php elseif ( 'Website' == bp_get_the_profile_field_name() ) : ?>

    bp_get_the_profile_field_edit_value allows you to display the field

  3. grezza
    Member
    Posted 1 year ago #

    Hi shawnyuan,

    Thanks for this.

    What im trying to do is get a list of checkboxes which have been defined as profile fields. So for example a field called "interests" which has say 10 checkboxes. I want to use that same profle field as options to tag posts with and save it as part of the posts metadata. Which means i can relate posts to users interests.

    "bp_get_the_profile_field_edit_value" i guess would work whilst looping through all profile fields, but i want to grab a specific field and then display at as a form on the post admin page and the save the selected values as meta for the post.

    Hope that makes sense

  4. shawnyuan
    Member
    Posted 1 year ago #

    Use the following code to grab the specific field you want.

    <?php if ( 'interests' == bp_get_the_profile_field_name() ) : ?>
    	<?php $interests = bp_get_the_profile_field_edit_value() ?>

    To add custom meta value to the post, start here: http://codex.wordpress.org/Custom_Fields. This allows you to get the custom field saved with each post. But for the custom field to appear with each post (with the 10 checkboxes), you'll have to add the meta field in manually.

Topic Closed

This topic has been closed to new replies.

About this Topic