我试图在循环运行后捕获wp_query中可用的所有id,并将它们放入数组中.我会将这些ID用于以后的功能.
我试过这个,但是有更好的方法吗?
$temp = array();
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$temp[] = $wp_query->post->ID ;
endwhile;
print_r($temp);
Run Code Online (Sandbox Code Playgroud)
得到这个:
数组([0] => 7050 [1] => 8227 [2] => 8206 [3] => 8202 [4] => 8200 [5] => 8190 [6] => 8180 [7] => 8174 [8] => 8172 [9] => 8168 [10] => 8162 [11] => 8150 [12] => 8144 [13] => 8138 [14] => 8132 [15] => 8134 [16 ] => 8130 [17] => 8126 [18] => 8128 [19] => 8124)
使用
get_the_ID()
Run Code Online (Sandbox Code Playgroud)
插话的
the_ID() ;
Run Code Online (Sandbox Code Playgroud)
试试这个
$temp = array();
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$temp[] = get_the_ID() ;
endwhile;
print_r($temp);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5059 次 |
| 最近记录: |