0
$args = array(
    'post_type' => 'lirik_melayu',
    'orderby'  => array( 
            'ID' => 'DESC' ,
        ),
);
$query = new WP_Query( $args );
$query_contents=Array();
while ( $query->have_posts() ) {
    $query->the_post();
    array_push($query_contents,Array(
        "id"=>get_the_ID(),
        "title"=>get_the_title(),
        "url"=>get_permalink(),
    ));
    echo get_the_title()."<br />";
}

It will loop until Ten post only..

It should be 14 post! Why it loops until TEN ONLY?

1 Answer 1

1

Just found the answer..

Add posts_per_page in the arguments as -1.

It should look like this:

$args = array(
    'post_type' => 'lirik_melayu',
    'posts_per_page'=> -1,   // set the limit post to UNLIMITED (-1 is unlimited)
    'orderby'  => array( 
            'ID' => 'DESC' ,
        ),
);
$query = new WP_Query( $args );
$query_contents=Array();
while ( $query->have_posts() ) {
    $query->the_post();
    array_push($query_contents,Array(
        "id"=>get_the_ID(),
        "title"=>get_the_title(),
        "url"=>get_permalink(),
    ));
    echo get_the_title()."<br />";
}
1
  • Yes, the posts_per_page argument must be set to -1 to result in ALL posts available. Jan 24, 2016 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.