Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to add fields from xprofile fields groups created by me


  • Saurabh Jain
    Participant

    @saurabhsjain91

    Hello all,
    How should i show xprofile fields from newly created xprofile groups into user profile.
    I added new fields in Base group and the fields shown in signup but i can’t find any way to show fields which i created in new group.
    Wordpress version : 3.9.2
    BuddyPress version : 2.0.2

    Thanks in advance

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

  • 1a-spielwiese
    Participant

    @1a-spielwiese

    Do you have inserted text (information) into the fields and profiles at issue?

    If you have old profiles and create later new fields, this fields are of course empty. So you have to update the profile information at first.


    danbp
    Moderator

    @danbp


    Saurabh Jain
    Participant

    @saurabhsjain91

    Thanks @1a-spielwiese and @danbp,
    I created new fields and didn’t updated profile that was the reason of not showing.

    Is there any way i can access the data in the fields. I created field named Skill i want to access the data in that field and use in other pages/post.


    1a-spielwiese
    Participant

    @1a-spielwiese

    Yes, within the administration area of your WordPress-installation is a menue point “users”. There is every user listed, and you as administrator can update all profiles – and the users themselves can update their own profile.


    Saurabh Jain
    Participant

    @saurabhsjain91

    Thanks @1a-spielwiese,

    Is there any way to search users using xprofile fields.
    E.g. In my xprofile field i have named “Skills” i want to search all user having the Skill = I.T.
    I made Skills as checkbox.


    1a-spielwiese
    Participant

    @1a-spielwiese

    I don’t know, whether this is possible in the administration area.

    But may you can adapt this for your purposes:

    https://buddypress.org/support/topic/add-profile-field-to-order-by-drop-down-menu/

    I guess, to order the members due to a certain field implies to see, whether it is filled in or not.


    danbp
    Moderator

    @danbp

    The solution below is valuable for front-end publishing only.

    If you want to see the “skill” profile field data on another page, like a custom page, you have to add a placeholder (do_action(the_skill) to this page template.

    As you’re outside of the profile loop, you also have to fetch a user_id to get the data.

    Add this function into the child-theme functions.php or into bp-custom.php

    function bpfr_field( $custom_field ) {
    	global $bp;
    	
    	// is xprofile component active ?
    	if ( bp_is_active( 'xprofile' ) )
    	
    	// fetch the user_id
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	
    	// fetch the data
    	$custom_field = xprofile_get_field_data('42', $current_user_id); // 42 is a field ID
    	
    	// show the data
    	echo '<div class="authorinfo">'. $custom_field . '</div>';
    	
    }
    add_action( 'myfield', 'bpfr_field', 1 );

    And this piece of code goes into the template.
    <?php do_action( 'myfield'); ?>

    Of course you can also use an existing placeholder. In this case, you just have to modify the add_action ($placeholder, $function)


    Saurabh Jain
    Participant

    @saurabhsjain91

    Thanks @danbp,
    Its cool thanks for answer, Will make changes according to me but u made me damn happy. Thanks once again.

    Thanks @1a-spielwiese too


    danbp
    Moderator

    @danbp

    @saurabhsjain91
    you asked for searching members by xprofile value. You want this on the member directory or in the backend ?

    Add custom filters to loops and enjoy them within your plugin

    https://codex.buddypress.org/plugindev/using-bp_parse_args-to-filter-buddypress-template-loops/
    See xprofile in Conclusion chapter.


    Saurabh Jain
    Participant

    @saurabhsjain91

    Hi @danbp, Thanks for all help it will help me more. For myself i made changes to code given by you and i was able filter members(users) according to skills(xprofile field) from this:

    function bpfr_field( $skill_field) { //$skill_field imported from do_action function
    	global $bp;
    	
    	// is xprofile component active ?
    	if ( bp_is_active( 'xprofile' ) )
    	
    	// fetch the user_id
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	   $blogusers = get_users( ); //to get all user data from database
    	   
    	// Array of WP_User objects.
    	foreach ( $blogusers as $user ) {
    	// fetch the data
    		$sk = xprofile_get_field_data('8', $user->ID); // 8 is a field ID
    		// show the data
    		foreach($sk as $skill){
    			 if ($skill == $skill_field){
    			 	echo '<div class="authorinfo"><a href="http://YOUR_URL/members/' . $user->user_login . '/profile"
    			 	 target="_blank">' . $user->display_name . '</a></div>'; //to add link for user profile
    			 	}
    			 }
    		
    	//echo '<span>' . esc_html(  ) . '&nbsp</span>';
    	} 
        
    	
    }
    add_action( 'myfield', 'bpfr_field');
    

    I made a dropdown to select and skill value and attached it to do_action like this

    do_action( 'myfield', $skillname );

    and it worked.

    Thanks for your support, 1000 likes to your answer and help 🙂


    danbp
    Moderator

    @danbp

    You’re welcome ! Glad you got it to work. ,;-)

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] How to add fields from xprofile fields groups created by me’ is closed to new replies.
Skip to toolbar