2016-06-22 3 views
0

私はwordpressで人気のあるユーザーの投稿を表示したいので、このコードで人気のあるユーザーIDを取得できます。どのように私はワードプレスで特定のユーザーの投稿を表示できますか?

 $user_query = new WP_User_Query(array( 
      'meta_query' => array (
       array (
        'key' => 'wp_popular_users', 
        'value' => $user_id, 
        'compare' => 'LIKE' 
        ) 
       ))); 
     if (! empty($user_query->results)) { 
      foreach ($user_query->results as $user) { 
       echo $user->ID. ', '; 
      } 
     } 

とこのコードで投稿を表示できます。例えば

    $the_query = new WP_Query(array(
         "posts_per_page"=>8, 
         "post_type"=>"post", 
         'author__in'=> array(POPULAR USER IDS HERE!!!), 
         "paged"=>$paged 
         )); 

        while ($the_query->have_posts()){ 
         $the_query->the_post(); 
         get_template_part('template-parts/content', 'profile-post'); 
        } 

が、私はこれらの2つのコードを組み合わせることができませんでした、私は=>配列 'author__in' にユーザーIDSを挿入する必要があります(ここでは一般的なユーザーのIDS !!!)、:1.5 、7

どうすればいいですか?回答ありがとう

+0

先頭のスクリプトを、その配列に呼び出す関数にラップさせますか?私はここで完全なシナリオを得ていると100%は確信していません。以下の答えも同様に機能するはずです。 – Rasclatt

答えて

1

これが動作するかどうか試してみることができますか?

$popularUsers = Array(); 
    $user_query = new WP_User_Query(array( 
     'meta_query' => array (
      array (
       'key' => 'wp_popular_users', 
       'value' => $user_id, 
       'compare' => 'LIKE' 
       ) 
      ))); 
    if (! empty($user_query->results)) { 
     foreach ($user_query->results as $user) { 
      echo $user->ID. ', '; 
      $popularUsers[] = $user->ID; 
     } 
    } 

    $the_query = new WP_Query(array(
        "posts_per_page"=>8, 
        "post_type"=>"post", 
        'author__in'=> $popularUsers, 
        "paged"=>$paged 
        )); 

       while ($the_query->have_posts()){ 
        $the_query->the_post(); 
        get_template_part('template-parts/content', 'profile-post'); 
       } 
+0

非常にありがとうございました@Yash Dayal –

関連する問題