Skip Navigation

[Resolved] Favorite counter

This support ticket is created 7 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 7 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#538230

With the plugin https://wordpress.org/plugins/wp-favorite-posts/ I have made the ability to add and browse "favorite" posts.
On the appropriate subpage it is inserted using shortcode [wptypes_listvfav] [/ wptypes_listvfav].
I want to add a counter that will show the currently logged in user the number of "favorite" posts he has added. Something like "[wpv-found-count] in [wptypes_listvfav]". Unfortunately I do not know how to save it correctly.

Posts for "favorite" are added via AJAX. It would be good if the counter also changed the number of posts added as soon as a new post was added, or removed a post previously added.

Code to display "Favorites":

function wptypes_listvfav_func($atts=array(), $content=null)
{
extract( shortcode_atts( array(), $atts ) );
if (function_exists('wpfp_get_users_favorites')):
$favorite_post_ids = wpfp_get_users_favorites();

$limit = 10;
$content .= "";
    if ($favorite_post_ids):
    $c = 0;
    $favorite_post_ids = array_reverse($favorite_post_ids);
    foreach ($favorite_post_ids as $post_id) {
    if ($c++ == $limit) break;
    $p = get_post($post_id);
		$content .= render_view_template(1757, $p);
    }
    else:
    $content .= "";
    $content .= "<h4 class='fav-empty'>Tu jest miejsce na Twoje ulubione ogłoszenia</h4>";
    $content .= "";
    endif;
    $content .= "";
endif;
return $content;
}
add_shortcode('wptypes_listvfav', 'wptypes_listvfav_func');

I will be grateful for help.

#538457

Dear Bochnacki,

They are custom codes questions, according to our support policy, we do not provide custom code support:
https://toolset.com/toolset-support-policy/

Here are my suggestions:
Q1) I want to add a counter that will show the currently logged in user the number of "favorite" posts he has added
I assume you are going to count how many "favorite" posts does current user have, if it is, you can count the var $favorite_post_ids, for example:

     count($favorite_post_ids);

More help:
hidden link
Count all elements in an array, or something in an object

Q2) Posts for "favorite" are added via AJAX. It would be good if the counter also changed the number of posts added as soon as a new post was added, or removed a post previously added.
Your are using function wpfp_get_users_favorites to get the values, which is out the range of Toolset, I suggest you contact the author of "wp-favorite-posts" plugin for it.

#540418

Thank you for the tips. The subject can be closed.
How can I do this, I will write a solution here.

#540427

You can post the solution here, then it will be shared to other users. thanks