source

Wordpress에서 모든 포스트 ID를 가져오는 방법

myloves 2023. 4. 3. 21:52

Wordpress에서 모든 포스트 ID를 가져오는 방법

나는 모든 게시물을 워드프레스 방식으로 받고 싶다, 나는 시도했다.

<div class="pppp" style="display:none">
<?php $post_ids = get_posts(array(
    'fields'        => 'ids', // Only get post IDs
));
var_dump($post_ids);
?>
</div>

단, 마지막 포스트 ID는 5개만 반환됩니다.

 array(5) {   [0]=>   int(35102)   [1]=>   int(35097)   [2]=>   int(35094)   [3]=>   int(33281)   [4]=>   int(33279) } 

내 워드프레스 사이트의 모든 포스트ID를 얻는 방법을 알고 싶습니다.

참고 자료: https://developer.wordpress.org/reference/functions/get_posts/ #source

function get_posts( $args = null ) {
    $defaults = array(
        'numberposts' => 5,
        'category' => 0, 
        'orderby' => 'date',
        'order' => 'DESC', 
        'include' => array(),
        'exclude' => array(),
        'meta_key' => '',
        'meta_value' =>'',
        'post_type' => 'post',
        'suppress_filters' => true
    );
....
}

어레이에 다음과 같은 것을 추가해야 합니다.

get_posts(array(
    'fields'          => 'ids', // Only get post IDs
    'posts_per_page'  => -1
));

주의: 'numberposts' 및 'posts_per_page'는 서로 바꾸어 사용할 수 있습니다.

언급URL : https://stackoverflow.com/questions/39426336/how-to-get-all-post-ids-in-wordpress