Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    $user_favs = wpfp_get_users_favorites($curauth->display_name);
    $fav_array = wpfp_get_users_favorites($user_favs);
    $fav_count = count($fav_array);
    echo '<div id="count">My Favourites (' . $fav_count .')</div>';
    ?>

    working code =)

    `<?php
    $user_favs = wpfp_get_users_favorites($curauth->display_name);
    $fav_array = wpfp_get_users_favorites($user_favs);
    $fav_count = count($fav_array);
    echo ‘<div id=”count”>My Favourites (‘ . $fav_count .’)</div>’;
    ?>`
    working code =)

    Hi, I tried this code however when a user is logged in and hasn’t got any favourites, it was saying the user had 1 favourite.

    I had to make the following changes in the wp-favourite-posts.php alongside your code to make it work:

    From:

    function wpfp_get_users_favorites($user = "") {
        $favorite_post_ids = array();
    
        if (!empty($user)):
            return wpfp_get_user_meta($user);
        endif;

    To:

    function wpfp_get_users_favorites($user = "") {
        $favorite_post_ids = array();
    
        if (!empty($user)){
            return wpfp_get_user_meta($user);
    	} else{
    		return 0;
        }

    EDIT:
    In order to get this working I had to adapt the code provided by Hellnik to:

    $current_user = wp_get_current_user();
    $user_favs = wpfp_get_users_favorites($current_user->display_name);
    $fav_count = count($user_favs);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to show favourite post count in widget’ is closed to new replies.