Skip to:
Content
Pages
Categories
Search
Top
Bottom

Find the new field_ name/id in the database?


  • tipsy
    Participant

    @tipsy

    Hey, I’m kinda stuck for a day now got a tips to check the database, but can’t find any solution.

    I use this to get a avatar:
    <?php echo get_avatar(1); ?>

    Then I use this to get the name:

    <?php 
    	$user_id = 1;
    	$key = 'first_name';
    	$single = true;
    	$user_first = get_user_meta( $user_id, $key, $single ); 
    	echo '<span>' . '' . $user_first . '</span>'; 
    ?>

    This above works great but when I now have created “profile fields” with BuddyPress in the user area I trying to do the same thing but can’t get the right result out of it.

    <?php 
    	$bp_get_member_user_id = 1;
    	$key = 'field_2';
    	$single = true;
    	$user_last = bp_get_user_meta( $bp_get_member_user_id, $key, $single ); 
    	echo '<span>' . '' . $user_last . '</span>';  
      ?>

    In this code above I have found that the field has the name field_2, but this aint right? If I change it to first_name it generate the first_name How can I find the real field name?

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

  • tipsy
    Participant

    @tipsy

    This solved it:

    $field = xprofile_get_field_data(2, $user_id); 
    echo '' . $field . '';

    If someone have a better solution, shoot!


    danbp
    Participant

    @danbp

    hi @tipsy,

    You didn’t explain what you wanted to achieve , so it’s a bit difficult to give a precise answer… but glad you got it ! 😉

    Your solution, a bit simplier

    $field = xprofile_get_field_data( '2', $user_id ); 
    echo $field;

    Here two examples. The first allows to publish a video on the profile and works only if you’re in the member loop. The second does the same thing, but outside of the loop and need that you add an action hook to your template where the vid should play. When outside of the loop, you need always a user_id

    function set_video_field( $field_value ) {
    	$bp_this_field_name = bp_get_the_profile_field_name();
    	// field name (case sensitive)
    	if( $bp_this_field_name == 'Video' ) {
    		$field_value = strip_tags( $field_value );
    		$field_value = '<iframe width="420" height="315" src="http://www.youtube.com/embed/'.$field_value.'" frameborder="0" allowfullscreen></iframe>';
    	}
    	return $field_value;
    }
    add_filter( 'bp_get_the_profile_field_value','set_video_field');

    For outside the loop. Add do_action( 'myfield' ); into a custom template.

    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('24', $current_user_id); // the field ID
    
    	$output = '<iframe width="420" height="315" src="http://www.youtube.com/embed/'.$custom_field.'" frameborder="0" allowfullscreen></iframe>';
    	
    	// show the data
    	if ( is_user_logged_in() && !empty( $custom_field ) ) :
    		echo '<div class="authorinfo">'. $output . '</div>';
    	endif;
    }
    add_action( 'myfield', 'bpfr_field', 1 );
    

    May this help ?


    tipsy
    Participant

    @tipsy

    Yes thank you @danbp, that were useful. Version 01 is working but I’m kinda stuck in another task. So I open a new question now!


    rezon8dev
    Participant

    @rezon8dev

    I see how this is working but I’m still lost as to why you cannot display on the member profile page. Can anyone tell me what is happening to prevent oembed content from rendering on the profile pages?


    danbp
    Participant

    @danbp

    @rezon8dev,

    why can’t you display something on the profile page ? Both snippets are working and display some content. Explain what you’re trying to achieve or test the snippet and give details about things which are not going like you want.

    Profiles are showed one a page called Member. This page is part of BP and use the page context of WordPress internally, to generate dynamically BP’s content.

    This means you cannot publish directly on this page, like an ordinary WP page. And all BP pages are working like this.
    This means you can’t publish directly on them, using wp’s editor. For any specific content you want evtl. to show on a BP page, you have to generate it separatly, by coding a function.
    That’s why the example above uses an iframe for the video.

    Normaly, when you add a video to a wp post or page, you have just to copy/paste a link and WP does the whole code automatically for you.

    But as it is a BP page, this is not avaible and you must add it manually.

    More generally, WordPress doesn’t allow any kind of media and you can only show those which are allowed/recognized by the CMS. This rule is explained here and concern any type of site and any plugin, including BP.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Find the new field_ name/id in the database?’ is closed to new replies.
Skip to toolbar