Fetch Selected Fields in WP_Query Class in WordPre

2019-08-06 00:04发布

问题:

I want to fetch selected fields in WP_Query Class in WordPress. I didn't find any argument for the same.

args=array('tag' => $tagname,'showposts'=>$no_of_post,'caller_get_posts'=>1);
$my_query = new WP_Query($args);

I need only title and description of the post. How to pass selected field in WP_Query function ?

回答1:

I do not really understand the question, but I will try to answer .

First of all, WP_Query is not a function, it is a class.

So after you do $my_query = new WP_Query($args); the class object is available.

That means that after setting up the data , you just use it normally if you want a loop for example :

while ( $my_query->have_posts() ) :
    $my_query->the_post();
    echo '<li>' . get_the_title() . '</li>';
   ... continue your loop

or $post->ID after setting the post data ( or $post->title )

Or access it directly :

$my_query->post->ID

All the post details are available normally, But I am not sure what you mean about description, do you mean excerpt ??



标签: wordpress