Re: How to list content relevant to a logged-in member’s interests (WAS: 1.2.6 upgrade – xprofile_get_fi
Doh! You know, I was using explode() later on to extract the individual elements – don’t know why I didn’t think of using implode() to clean up the array.
Thanks @hnla – that works now. For reference, here is the full code – basically this uses the data derived from checkboxes in the member’s profile (in this case it’s called “Areas of Interest” with the field ID of 25 – change this to reflect your name/field ID) to hunt down related content tags and display a random list of content relevant to that member (remember to put the code mentioned by @boonebgorges (above) in your theme’s functions.php):
`
<?php //for use in the loop, list 5 post titles related to user profile interest areas – checkboxes in extended profile
$backup = $post; // backup the current object
//Fetch profile tags from custom field ‘Areas of Interest’ and clean up data
$profileTagFull = xprofile_get_field_data( ’25’ , bp_loggedin_user_id() );//Fetch the text for the tags
$profileTagClean = implode( ‘, ‘, $profileTagFull);//Clean up the data
$profileargs=array(
‘tag_slug__in’ => explode( ‘, ‘, $profileTagClean ),
‘post__not_in’ => array($post->ID),
‘showposts’=>5,
‘orderby’ => rand,
‘order’ => DESC,
‘caller_get_posts’=>1
);
?>
Content of Interest
()
-
<?php
- cat_name . ‘: ‘; ?><a href="” rel=”bookmark” title=””>
- No related content
$profile_query = new WP_Query($profileargs);
if( $profile_query->have_posts() ) {
while ($profile_query->have_posts()) : $profile_query->the_post(); ?>
<?php endwhile;
} else { ?>
<?php }
$post = $orig_post;
wp_reset_query();
?>
`
Thanks to @hnla @r-a-y and @boonebgorges for their help.