只查询帖子的标题/字段/特色媒体

时间:2016-09-30 作者:VSB

我将开发一个Wordpress插件作为移动应用程序的webesrvice。我怎样才能在wordpress插件中只获得帖子的标题/id/特色媒体?我看了一下wordpress developer documentation, 它将返回帖子列表,并可以过滤它们,但它会返回帖子的所有信息,但为了提高效率,我只需要3个字段{id,title,featured media}。

如何在wordpress中查询此信息,而不是整个帖子信息?

1 个回复
最合适的回答,由SO网友:Rishabh 整理而成

您可以这样进行查询

$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1; 

$args = array(
    \'post_type\' => \'post\',  //Specyfying post type
    \'cat\'=> 1,    //Selecting post category by ID to show
    \'posts_per_page\' => 10,  //No. of posts to show     
    \'paged\' => $paged       //For pagination
);

$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();
    //To show Title of post
    the_title();     
    //To show ID of post
    $id = get_the_ID();
    echo $id;   
    /*****     Featured Media     ******/
the_post_thumbnail(
array(120, 90),   //Width and height of featured image
    array(

    \'class\' => \'thumbnail\',   //class to apply css properties
    \'alt\' => \'post thumbnail\', //Alternate text if there is no image to show
    \'title\' => \'my custom title\' //Title to specify
)
);
/*******     Featured Media Ends   ********/
endwhile;