在 WordPress 中获取 WP_Query 类中的选定字段 [英] Fetch Selected Fields in WP_Query Class in WordPress
问题描述
我想在 WordPress 的 WP_Query 类中获取选定的字段.我没有找到任何相同的论据.
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);
我只需要帖子的标题和描述.如何在 WP_Query 函数中传递选定的字段?
I need only title and description of the post. How to pass selected field in WP_Query function ?
推荐答案
我不是很明白这个问题,但我会尽量回答.
I do not really understand the question, but I will try to answer .
首先,WP_Query 不是一个函数,它是一个类.
First of all, WP_Query is not a function, it is a class.
所以在你执行 $my_query = new WP_Query($args);
之后,类对象就可用了.
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
或 $post->ID
设置帖子数据后(或 $post->title
)
or $post->ID
after setting the post data ( or $post->title
)
或者直接访问:
$my_query->post->ID
所有帖子的详细信息都可以正常使用,但我不确定您对description
的意思,您的意思是excerpt
??
All the post details are available normally, But I am not sure what you mean about description
, do you mean excerpt
??
这篇关于在 WordPress 中获取 WP_Query 类中的选定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!