2017-12-27 11 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

안녕을 경우 당신을 위해 전체이 응답 도움? – developerme

0

wordpres 게시물 미리보기 이미지는 메타 메타 데이터와 함께 작동합니다. 그리고 썸네일 메타 키는 _thumbnail_id입니다. 이 메타 키를 사용하여 쿼리를 생성 할 수 있습니다. 자세한 내용 : Wordpress Meta Query

또는만을 포함 썸네일 (_thumbnail_id meta_key) 게시물이 쿼리 사용할 수 있습니다

$args = array(
    'meta_key' => '_thumbnail_id', 
    'posts_per_page' => 3 
); 
$posts = new WP_Query($args);