Filter posts in loop using WP Favorite Posts

Hi there, I’m currently trying out this plugin and it’s been easy to setup; however, the way they display favorited posts is just a text list so I’m hoping to filter posts using something like if > favorited post > display in the pinegrow show posts loop.

I don’t know php very well and I’m not sure if this is even possible, help of any kind would be appreciated

@snowfeald,
I just took a look at the code for that plugin. The favorites can be stored in either local storage or the database, depending on user. That complicates things a little (I think). The post ids can be retrieved and looped through using the function wpfp_get_users_favorites($user). With some php you could loop through this to retrieve the favorited posts.
Bob

Hi Rob, so what would that actually look like in pinegrow in order to filter the posts in a loop? I don’t quite get what to do with the code here to make this work, I really need to learn php -_-

Cheers for your help thus far regardless of whether or not you go into greater detail!

Well, you would have a block of PHP to retrieve the post ids, and then you would have a query to retrieve them and output the contents. I’ll try to write it up later.

@snowfeald,
I just fooled around with this a little. I didn’t dig into the plugin code to see how the favorites were being set. Because of this I couldn’t use a standard loop, so basically I had to write some custom PHP - didn’t use any WordPress action.

<?php
$user = isset($_REQUEST['user']) ? $_REQUEST['user'] : "";
$favorite_post_ids = wpfp_get_users_favorites($user);
if ($favorite_post_ids){
	$favorite_post_ids = array_reverse($favorite_post_ids);
    foreach ($favorite_post_ids as $post_id) {
        ?>
        <a href="<?php the_permalink($post_id); ?>" title="<?php the_title_attribute($post_id); ?>"><?php echo esc_html(get_the_title($post_id));?></a>
        <?php $the_content = apply_filters('the_content', get_the_content($post_id);?>
        <p><?php echo $the_content; ?> </p>
        <?php        
    }
}
?>

So this checks for the user id. If it exists it uses the function wpfp_get_users_favorites() from the plugin to get an array of the post ids. Then it runs through each, outputing the title as a link, followed by the content. You can change this up how you would like it displayed. This also doesn’t take into account the number of posts to show that the plugin defines.
I guess to do this more correctly I would have to look at what the wpfp_get_users_favorites() does and how the favorites are stored. Then I could use a proper loop. I guess I would also use wpfp_get_options() to get the limit.
Anyway, this is a good starting point. If you want to try to alter this more to your liking I can help.
Bob