WP Favorite Posts
Display amount of favorites for individual custom post types (3 posts)

  1. lildragn
    Posted 3 years ago #

    Hello all, I'm currently trying to alter chacha2000 code here for use on custom post types and I can't quite seem to figure it out. Any WP experts here care to help? Would be greatly appreciated!

    This is the existing code from this above thread

    function wpfp_get_current_count() {
        global $wpdb;
    	$current_post = get_the_ID();
        $query = "SELECT post_id, meta_value, post_status FROM $wpdb->postmeta";
        $query .= " LEFT JOIN $wpdb->posts ON post_id=$wpdb->posts.ID";
        $query .= " WHERE post_status='publish' AND meta_key='wpfp_favorites' AND post_id = '".$current_post."'";
        $results = $wpdb->get_results($query);
        if ($results) {
            foreach ($results as $o):
                echo $o->meta_value;
        }else {echo( '0' );}

    then place this <?php wpfp_get_current_count(); ?>

    Thanks for any help


  2. Carol
    Posted 3 years ago #

    Would you like display amount for each post...?!

    I used this code on my functions.php...

    function postfavorited(){
    	$postfavorited = get_post_meta(get_the_ID(), 'wpfp_favorites', true);
    	if($postfavorited != ''){
    		echo $postfavorited .' Favorited'; }

    and in my loop of each post:
    <?php postfavorited() ?>

  3. lildragn
    Posted 3 years ago #

    Wow that works great! Thank you very much.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Favorite Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.