admin管理员组文章数量:1392047
Suppose I have two categories A
and B
. Now I have uploaded some Posts A1
, A2
under Category A
and B1
, B2
under Category B
. Also for every Posts
I have added some new custom fields using ACF
plugin like thumbnail_image
, first_image
,second_image
,third_image
. I have added image for better understand below.
So if I want to retrieve all the Posts
of Category A
with their custom fields what is the Query.
Anybody help please ? thanks in advance
Suppose I have two categories A
and B
. Now I have uploaded some Posts A1
, A2
under Category A
and B1
, B2
under Category B
. Also for every Posts
I have added some new custom fields using ACF
plugin like thumbnail_image
, first_image
,second_image
,third_image
. I have added image for better understand below.
So if I want to retrieve all the Posts
of Category A
with their custom fields what is the Query.
Anybody help please ? thanks in advance
Share Improve this question edited Feb 3, 2020 at 6:30 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 1, 2020 at 15:38 Arafat RahmanArafat Rahman 1011 Answer
Reset to default 0You can use this code,
$args = array(
'cat' => 4, // Category ID
// 'category_name' => 'staff', // Category Name
'posts_per_page' => -1,
)
// The Query
$query = new WP_Query( $args );
// The Loop
while ( $query->have_posts() ) {
$query->the_post();
$thumbnail_image = get_post_meta( get_the_ID(), 'thumbnail_image', true );
$first_image = get_post_meta( get_the_ID(), 'first_image', true );
$second_image = get_post_meta( get_the_ID(), 'second_image', true );
$third_image = get_post_meta( get_the_ID(), 'third_image', true );
}
本文标签: Query for getting posts with their custom fields data in Wordpress
版权声明:本文标题:Query for getting posts with their custom fields data in Wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744781890a2624763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论