Caesar Caesar - 3 years ago 195
jQuery Question

only shows the first 10

Why it only shows 10 post results even if there are more?



<div class="job-cont">
<?php
$query = new WP_Query( array( 'post_type' => 'jobs' ) );

if ( $query->have_posts() ) :

while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="title_image_container">
<a href="<?php the_permalink (); ?>">
<h1 class="the_job_title"><?php the_title(); ?></h1>
<img class="the_job_image" src="<?php the_post_thumbnail ();?>
</a>
</div>
<?php endwhile;

endif;
?>

</div>





It's there a way to change the number of posts that I want to be showed in the page?

I all ready tried this one, but without result yet:

function number_of_posts_per_page( $number ) {
if ( is_home() ) {
$number->set( 'posts_per_page', 15 );
}

add_action('pre_get_posts', 'number_of_posts_per_page');



Answer Source

Wordpress has default setting as 10 posts per page.

For blog posts, you can adjust settings in Settings -> Reading

For custom post type you can adjust maximum posts per page directly in loop query as in the code below where -1 means unlimited.

$query = new WP_Query( array( 'post_type' =>  'jobs', 'posts_per_page' => -1) );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download