반응형
get_posts()는 9를 반환해야 하는데 왜 일치하는 게시물을 5개만 반환합니까?
global $post;
$cat1=get_cat_ID('test1');
$cat2=get_cat_ID('test2');
$myrecentposts = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 5));
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2"));
$myrecentpostscount = count($myrecentposts2);
echo $myrecentpostscount;
에코 값은 5입니다(정확한 값은 9).포스트 카운트의 올바른 값을 반환하려면 $myrecentposts2 계산을 다음과 같이 변경하는 방법밖에 없습니다.
$myrecentposts2 = get_posts(array('post_not_in' => get_option('sticky_posts'), 'cat' => "-$cat1,-$cat2",'showposts' => 999));
워드프레스 코덱스에는 기본값이 있습니다.posts_per_page
의 가치5
.
이 제한을 제거하려면posts_per_page = -1
.
이 제한을 제거하려면nopaging = true
.
Codex의 문서를 보면 표시할 투고 수에 대한 파라미터가 있습니다.
파라미터는 다음과 같습니다.'posts_per_page'
사용방법:'posts_per_page'=> -1 // for removing the limit
모든 투고를 가져옵니다.
업데이트:'nopaging' => true
새로운 버전을 사용하는 방법
또한 WP 2.9(또는 2.8) 시점에서는 showposts는 권장되지 않습니다.반환되는 투고의 양을 제어하려면 posts_per_page를 사용하십시오.
언급URL : https://stackoverflow.com/questions/2134500/why-does-get-posts-return-only-5-matching-posts-when-it-should-return-9
반응형
'programing' 카테고리의 다른 글
React state vs Redux Store를 선택하는 경우 (0) | 2023.02.26 |
---|---|
gradle process 명령어 java가 0이 아닌 exit 값 1로 종료되었습니다. (0) | 2023.02.26 |
Wordpress 사이트 제목 표시 (0) | 2023.02.26 |
Angular에서 base64 데이터를 포함하는 변수를 사용하여 영상 src 로드JS (0) | 2023.02.26 |
@SpringBootConfiguration을 찾을 수 없습니다. 테스트에서 @ContextConfiguration 또는 @SpringBootTest(classes=...)를 사용해야 합니다. (0) | 2023.02.26 |