2017-12-27 37 views
0

私は3の特集された画像投稿を検索したいです。投稿に特徴画像がない場合、その画像は表示されません。投稿に特集画像がある場合は、3つの特集記事を表示します。どうやってやるの?Wordpress query 3特集画像投稿

global $wp_query; 
global $paged; 
$temp  = $wp_query; 
$wp_query = null; 
$wp_query = new WP_Query(); 
$wp_query->query('showposts=3&post_type=post&orderby=menu_order&order=ASC'.'&paged='.$paged); 
while ($wp_query->have_posts()) : $wp_query->the_post(); 

the_post_thumbnail(); 
the_title(); 

endwhile; 

答えて

0

以下の機能を使用できます。私はテストし、私のために働いていることを確認しました。

$recent_query = new WP_Query(
          array(
            'post_type'  => 'post', 
            'orderby'  => 'date',  
            'order'   => 'DESC', 
            'post_status' => 'publish', 
            'posts_per_page' => 3, 
            'meta_query'  => array(
                   array( 
                    'key' => '_thumbnail_id' 
                    ), //Show only posts with featured images 
                   ) 
            ) 

          ); 


if ($recent_query->have_posts()) : 
    while ($recent_query->have_posts()) : $recent_query->the_post(); 

     if (has_post_thumbnail()) { 
      the_post_thumbnail(); 
     } 

     the_title(); 

    endwhile; 

endif; 
+0

こんにちは??:Wordpress Meta Query

それとものみ含めるには、サムネイル(_thumbnail_id meta_key)このクエリを使用することができます記事を持っています – developerme

0

wordpresポストサムネイルはポストメタスで動作します。サムネイルのメタキーは_thumbnail_idです。このメタキーを使用してクエリを作成できます。詳細:あなたのための完全なこの答えのヘルプ場合

$args = array(
    'meta_key' => '_thumbnail_id', 
    'posts_per_page' => 3 
); 
$posts = new WP_Query($args); 
関連する問題