• Hi,

    I am trying to change the following code to list 10 posts:

    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc');
    	while ($the_query->have_posts()) : $the_query->the_post();

    I have tried the following without success:

    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page = 10');
    	while ($the_query->have_posts()) : $the_query->the_post();
    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page' => 10);
    	while ($the_query->have_posts()) : $the_query->the_post();
    $the_query = new WP_Query('showposts='. $posts .'&orderby=post_date&order=desc', 'posts_per_page=10');
    	while ($the_query->have_posts()) : $the_query->the_post();

    The first one does nothing, the second and third list PHP errors on loading the site.

    This code does list 10, but not in the way that I need:

    $loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => 10 ) );
    while ( $loop->have_posts() ) : $loop->the_post();
Viewing 2 replies - 1 through 2 (of 2 total)
  • this is the setting of the number of posts in your original code:

    'showposts='. $posts .'

    ‘showposts’ is deprecated for ‘posts_per_page; and $posts is a variable holding the number of posts to show.

    changing your code to the following should work:

    $the_query = new WP_Query('posts_per_page=10&orderby=post_date&order=desc');
    	while ($the_query->have_posts()) : $the_query->the_post();

    Thread Starter crisp82

    (@crisp82)

    This has not worked. The code is in the ‘theme-functions.php’ of the theme I am using (The morning after).

    Putting

    $the_query = new WP_Query('posts_per_page=10&orderby=post_date&order=desc');
    	while ($the_query->have_posts()) : $the_query->the_post();

    into the home.php will display 10 results, but it does not organise itself based on the CSS as the ‘Latest Post’ section does. Very frustrating!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP code change help needed!’ is closed to new replies.