我试图在循环运行后捕获wp_query中所有可用的id并将它们放入数组中。我将在后面的函数中使用这些 ID。
我试过这个,但有更好的方法吗?
$temp = array();
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$temp[] = $wp_query->post->ID ;
endwhile;
print_r($temp);
并得到这个:
阵列 ( [0
使用
get_the_ID()
的内嵌
the_ID() ;
试试这个
$temp = array();
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$temp[] = get_the_ID() ;
endwhile;
print_r($temp);