2012-01-19 63 views
0

我的問題是我怎麼能這個項目我有,通過$count_fb 看來我不能這樣$the_query = new WP_Query('orderby='.$count_fb.'&posts_per_page=6');WordPress的PHP排序查詢

奇怪的是,腳本工作,並顯示的鏈接,而不是爲了增加一個參考排序最高的$count_fb串 下面的代碼:

$the_query = new WP_Query('orderby='.$count_fb.'&posts_per_page=6'); 

while ($the_query->have_posts()) : $the_query->the_post(); 
$url = get_permalink($post->ID); 
$fb_file = file_get_contents('https://graph.facebook.com/?ids=' . $url); 
$json = json_decode($fb_file); 
$count_fb = $json->$url->comments; 

if ($count_fb == 0 || !isset($count_fb)) { 
$count_fb = 0; 
} 

echo 'https://graph.facebook.com/?ids='.$url.$count_fb; 
echo '<br />'; 

endwhile; 

wp_reset_postdata(); 
+0

$ count_fb應該是什麼?您是否檢查過codex中的可能性http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters? – kevin

+0

以及$ count_fb在while()獲得每6個wordpress帖子的評論數。我是一個初學者,我想,我不能使用while()中的變量() – ciprian

+0

你有任何代碼在循環外部獲取這個變量的內容$ count_fb嗎?因爲如果你只是在循環內部有一個它不能被應用到'while'。 – kevin

回答

0

你可以嘗試通過您的參數作爲一個數組,而不是字符串:

$query = new WP_Query(array ('orderby' => $count_fb, 'posts_per_page' => '6'));