This solved it:
$field = xprofile_get_field_data(2, $user_id);
echo '' . $field . '';
If someone have a better solution, shoot!
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 ?
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!
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?
@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.