kylephillips / favorites

Simple and flexible favorite buttons for any WordPress post type.
https://favoriteposts.com
223 stars 86 forks source link

If else syntax doesn't work when checking favorites count by post #105

Closed dennop closed 5 years ago

dennop commented 5 years ago

Hi @kylephillips I wanted to display different message depending on the favorites count on single.php template,

<?php  if ( get_favorites_count() < 5 ) { ?>
// show something
<?php } if ( get_favorites_count() >= 5 ) { ?>
// show something else
<?php } ?>

Unfortunately, it didn't work. Please help me. Also, I tried to put back the _$postid, still it cannot check the condition successfully.

kylephillips commented 5 years ago

The "get_favorites_count" function returns the count, wrapped in a span tag with data attributes necessary for ajax functionality.

With what you're trying to do, you'll need to specify the html parameter as false (3rd param).

Try this:

<?php
$favorites_count = get_favorites_count($post_id = null, $site_id = null, false);
if ( intval($favorites_count) < 5 ){
    // Show Something
} else {
    // Show Something Else
}