Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You may want to store number of comments to <a href="http://codex.wordpress.org/Custom_Fields" rel="nofollow">post meta-data</a> so you'll be able to use it for sorting later.</p> <p>BTW, your function will not work due to difference in response format you use and the real response. (number of comments is present in <code>response-&gt;comments-&gt;count</code> and not in <code>response-&gt;comments</code>). Also you may wish to use <code>fields=comments</code> to limit the response to only include details about comments without all the rest of data or using FQL query to retrieve only count of comments:</p> <pre><code>SELECT commentsbox_count FROM link_stat WHERE url = 'POST_URL' </code></pre> <p>The flow as I see it may be so:</p> <ul> <li>Store number of comments within post-meta</li> <li>Update number of comments calling <code>fb_comment_count</code> once post is viewed</li> <li>Use <a href="http://codex.wordpress.org/Function_Reference/query_posts" rel="nofollow"><code>query_posts</code></a> with <code>meta_key</code> to change the defaults.</li> </ul> <pre class="lang-php prettyprint-override"><code>function fb_comment_count() { global $post; $url = get_permalink($post-&gt;ID); $query = "SELECT commentsbox_count FROM link_stat WHERE url = '{$url}'"; $responseText = file_get_contents('https://graph.facebook.com/fql?q='.$query); $responseJson = json_decode($responseText); $commenteCount = $responseJson-&gt;data-&gt;commentsbox_count; update_post_meta($post-&gt;ID, 'facebook_comments_count, $commenteCount); // ... } </code></pre> <p>Once your posts have <code>facebook_comments_count</code> <a href="http://codex.wordpress.org/Function_Reference/get_post_meta" rel="nofollow">meta</a> you can use <code>query_posts</code> in <a href="http://codex.wordpress.org/The_Loop" rel="nofollow">The Loop</a>:</p> <pre><code>query_posts('posts_per_page=5&amp;meta_key=facebook_comments_count&amp;orderby=meta_value&amp;order=DESC') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload