I am showing posts by shortcode into posts/pages of WordPress, and want to show an infinite list of posts, but it is showing only 10 posts.
Here is my code; please guide me what is wrong with my query.
$args = array( 'post_type' => 'post', 'cat' => '2', 'meta_key' => 'issue_of_article', 'meta_value' => $issue, 'posts_per_page' => -1, 'orderby' => 'artcle_category', 'order' => 'ASC');
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$loop->the_post();
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
endwhile;
}
Just add this in your argument
then you are done.
One more thing: you can change the default setting from admin to something other than 10. Go to the WordPress admin – Settings – Reading. There is an option like “Blog pages show at most”. Type there the number of posts you want as the default.
Go to settings menu in the admin page
Settings -> Reading
Change the value for Blog pages show at most.
It will work.
Stupid question maybe but why do you call $loop->the_post(); twice ? Isn’t it the source of the problem ? (each loop calls 2 posts at a time)
You can decide how many posts to show in the loop:
or
Both of these should work.
At first – post WP questions at WordPress.Stackexchange.com
The good way is to add in
functions.php
:add_action(‘pre_get_posts’,’myfunc’);
function myfunc($query){
if ($query->is_main_query() && $query->is_archive){
$query->set( ‘posts_per_page’, 1000);
}
return $query;
}