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.
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.
Thank you for the tips. The subject can be closed.
How can I do this, I will write a solution here.
You can post the solution here, then it will be shared to other users. thanks