• I want to be able to display a user’s favorite posts when anyone views their profile. What code can I use to do this?

    I was thinking that maybe I can do something like:

    <?php wpfp_list_favorite_posts(); ?>

    but that only displays your favorites, and not the favorites of an individual user.

    I saw a thread that says you can use:

    wpfp_get_users_favorites(String userlogin)

    But that just gives you an array of the user’s favorite posts apparently. How do you actually display a person’s favorite posts?

    https://www.ads-software.com/extend/plugins/wp-favorite-posts/

Viewing 3 replies - 16 through 18 (of 18 total)
  • Thank you

    Khoiruddin

    at last i solve this problem by deleting AND $wpdb->usermeta.meta_key = 'wpfp_favorites'. I edited

    Khoiruddin

    ‘s code . Add this code in author.php it will show users’s favorite post in users’profile page .

    <?php
     $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    	global $current_user;
        get_currentuserinfo();
    	$meta_query = mysql_query("
    		SELECT distinct($wpdb->usermeta.meta_value) FROM
    		$wpdb->posts,  $wpdb->postmeta, $wpdb->users, $wpdb->usermeta
    		WHERE $wpdb->postmeta.post_id = $wpdb->posts.id
    		AND $wpdb->usermeta.user_id = $wpdb->users.id
    		AND $wpdb->postmeta.meta_key = 'wpfp_favorites'
    				AND $wpdb->users.id = '".$curauth->ID."'");
    
    	while($array_meta = mysql_fetch_array($meta_query))
    	{
    		$meta = explode('"',$array_meta['meta_value']);
    	}
    
    	class IndexFilter extends FilterIterator {
    		public function __construct (array $data) {
    			parent::__construct(new ArrayIterator($data));
    		}   
    
    		public function accept () {
    			return ($this->key() % 2);
    		}
    	}
    
    	$arr_meta	= $meta;
    	$posts_id = array();
    
    	foreach (new IndexFilter($arr_meta) as $key => $value) {
        $posts_id[$key] = $value;
    
    }
    
    ?>
    <h2>Favorite Posts</h2>
    <ul>
    <?php
    $data_posts_id = array_reverse($posts_id);
    foreach($data_posts_id as $show_posts_id){
    	echo '<li><a href="'.get_permalink($show_posts_id).'" title="Permanent link to '.get_the_title($show_posts_id).'">'.get_the_title($show_posts_id).'</a></li>';
    }
    ?>

    Thanks mate, but this one doesn’t show the favorite posts of the admin… Why is that?

    PS: Oomkaap’s code shows only the one of the admin… The rest of the users’ favorite posts are invisible.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘[Plugin: WP Favorite Posts] Display a user's favorites when viewing their profile’ is closed to new replies.