1

ループが実行された後、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] => 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)

4

1 に答える 1

7

使用する

get_the_ID()

のはめ込み

the_ID() ;

これを試して

$temp = array();
while ( $wp_query->have_posts() ) : $wp_query->the_post();
    $temp[] = get_the_ID() ;
endwhile;

print_r($temp);
于 2012-08-10T14:16:56.813 に答える