• Hi, first of all, thank you for this plugin! It seems to be exactly what we have been looking for.

    I am implementing it on an archive page where each post gets the heart icon to be favorited. The same archive page has a button link to the favorites page. I would like to output the favorites count on the archive page in the favorites button text.

    Is this possible right now?

    I tried to use the custom template, adding a boolean paramater that when set to true would return only the post_count, but it returns all posts of that type instead of only the favorited ones.

    How would I go about this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Takashi Matsuyama

    (@takashimatsuyama)

    Hi @lfbender

    Thanks for your question.

    Unfortunately, this plugin doesn’t have that option now.

    Could you please let me know for future reference.

    Are you looking for the number of the user’s own favorites, as in this shortcode ([ccc_my_favorite_list_menu]) ?
    Or is it the total number including other users ?

    custom template

    This is part of a sample code to write in “your-theme/functions.php”.

    function ccc_my_favorite_list_custom_template( $my_favorite_post_id=false ) {
      $args= array(
        'post_type' => 'any',
        'post__in' => $my_favorite_post_id,
        'orderby' => 'post__in',
        'posts_per_page' => -1,
      );
      $the_query = new WP_Query($args);
    

    shortcode: [ccc_my_favorite_list_custom_template]

    Please see the related topic for usage.

    Please, try it.
    Thanks

    Thread Starter lfbender

    (@lfbender)

    Hi @takashimatsuyama and thanks for the answer.

    I am already using the custom template.

    Yes, I would be interested in only the number of saved posts for the user and to display that number on an archive page saying, “You have saved 3 favorites”.

    Plugin Author Takashi Matsuyama

    (@takashimatsuyama)

    Hi @lfbender

    Thank you for your reply.

    Please, try this.

    function ccc_my_favorite_list_custom_template( $my_favorite_post_id=false ) {
      $args= array(
        'post_type' => 'any',
        'post__in' => $my_favorite_post_id,
        'orderby' => 'post__in',
        'posts_per_page' => -1,
      );
      $the_query = new WP_Query($args);
      if( $the_query->have_posts() ) {
    ?>
    <p id="ccc-favorite-count">You have saved <span class="number"><?php echo $the_query->post_count; ?></span> favorites</p>
    <div data-ccc_favorite-delete_all=true><a href="#" class="ccc-favorite-post-delete-button">All Delete</a></div>
    <?php
        while( $the_query->have_posts() ) {
          $the_query->the_post();
    ?>
    <div class="list-ccc_favorite">
      <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
      <div class="ccc-favorite-post-toggle"><a href="#" class="ccc-favorite-post-toggle-button" data-post_id-ccc_favorite="<?php echo $the_query->post->ID; ?>"></a></div>
    </div>
    <?php
        } //endwhile
      } //endif
    } // endfunction

    shortcode: [ccc_my_favorite_list_custom_template]

    Key Points: <p id="ccc-favorite-count">You have saved <span class="number"><?php echo $the_query->post_count; ?></span> favorites</p>

    If this isn’t the right solution, please let me know again.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Favorite counter’ is closed to new replies.