2017-12-12 15 views
0

내 웹 사이트에서 custom_post_type 목록을 표시하는 데 문제가 있습니다. 게시물을 가져올 수 있지만 작동하지 않는 것은 "post_per_page"입니다. 그것은 무시되고 그 유형의 모든 게시물을 얻습니다. 여기 맞춤 Post_per_page가 작동하지 않습니다.

가 내 홈 페이지에있는 코드입니다 (너무 다른 곳에서 작동하지 않습니다) :

<?php 
// 1ST 

$args = array(
    'post_type' => 'custom_post_1', 
    'post_per_page' => 1, 
); 

$custom_post_1 = new WP_Query($args); 

if ($custom_post_1->have_posts()) : while ($custom_post_1->have_posts()) : $custom_post_1->the_post(); ?> 

    // My content 

<?php endwhile; endif; wp_reset_postdata(); ?> 

<?php 
// 2ND 

$args = array(
    'post_type' => 'custom_post_2', 
    'post_per_page' => 3, 
); 

$custom_post_2 = new WP_Query($args); 

if ($custom_post_2->have_posts()) : while ($custom_post_2->have_posts()) : $custom_post_2->the_post(); ?> 

    // My content 

<?php endwhile; endif; wp_reset_postdata(); ?> 

<?php 
// 3RD 

$args = array(
    'post_type' => 'custom_post_3', 
    'post_per_page' => 1, 
); 

$custom_post_3 = new WP_Query($args); 

if ($custom_post_3->have_posts()) : while ($custom_post_3->have_posts()) : $custom_post_3->the_post(); ?> 

    // My content 

<?php endwhile; endif; wp_reset_postdata(); ?> 

사전에 감사!

답변

2

posts_per_page하지 post_per_page 내 친구

+0

... 정말 감사합니다! –

0

posts_per_page 대신 post_per_page 될 것이다 따라, WP_Query의 pagination 매개 변수를 참조하십시오.

https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

그래서이 사람은 도움이되기를 바랍니다

$args = array(
    'post_type' => 'custom_post_1', 
    'posts_per_page' => 1, 
    'post_status' => 'publish', 
); 

$custom_post_1 = new WP_Query($args); 

, 다음과 같이 쿼리가 될 것이다 따라 :) 내가 너무 바보 기분

+0

너무 고맙습니다. –

+0

환영합니다. 친구 upvote –

+0

을 잊지 마세요. 내 담당자가 게시 점수 인상을 표시하기에는 너무 낮습니다. 그것은 어쨌든 기록됩니다;) –