You are using the count()
function to determine $liked_count
. This function is meant to determine the number of items in an array. But it appears that the value stored in the liked_count
postmeta is not an array, but an integer count. When you do count( $p )
where $p
is an integer, you get 1
no matter what the integer is.
Try this instead:
$liked_count = (int) get_post_meta( $id, 'liked_count', true );