Function returns post URLs rather than retrieving Facebook Graph API data

require('../wp-blog-header.php');
query_posts('&showposts=-1&order=ASC');

while (have_posts()) : the_post();

        $url = the_permalink();
        $json = file_get_contents( 'https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27' . $url . '%27' );
        $json_data = json_decode($json, false);
        echo $json_data->data[0]->total_count;
        echo '<br>';

    endwhile;

The above code, rather than returning the total share count, it returns the posts URLs.

How can I make it return the total_count value for each post ? I suspect line 6 needs to return URLs first before next line does the task..

Read More

Regards,

Thanks!

Related posts

Leave a Reply

1 comment

  1. Someone in the WordPress Development network pointed me to this:

    the_permalink(); doesn’t return the permalink, it prints it, so I should use get_the_permalink(); instead:

    $url = get_the_permalink();