0

Problem : I'm trying to display few post on my WP front page, so I used query_post to get post using some filtering argument and it's giving perfect result. Problem happens when pagination added in this query. First page is showing without any issue but res from page 2 to end it's just shown a 404 page. If I use same code on another page instead of front page or index.php it's working fine. The same code also worked on any templates also.

Spec : WP 3.9, xaamp / online server php 5.3

Solution Tried :

  1. making $paged global, failed.
  2. using pagination plugin, failed.
  3. using custom pagination designed by me, failed.
  4. using page if paged variable not exists, failed.
  5. using wp_query, failed.

    <?php
        // Get all posts under category testimonials.
        // The Query
        global $paged;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $wp_query = new WP_Query();
          $wp_query->query('showposts=2'.'&paged='.$paged);
          /*query_posts( array (
          'posts_per_page' => 2,
          'paged' => $paged
          ) );*/
          // The Loop
          if ( have_posts() ) : while ( have_posts() ) : the_post(); $post_id =get_the_ID();
     ?>
    
1
  • Never ever use query_posts or use the $wp_query variable. In both instances, you break the main query object. Use a unique query variable and use WP_Query Jul 20, 2015 at 4:23

2 Answers 2

2

if you use static front page then, use get_query_var('page') instead of get_query_var('paged'). hope it will work!

$paged = (get_query_var('page')) ? get_query_var('page') : 1;
-1

Try this

global $query_string;
    parse_str( $query_string, $my_query_array );
    $paged = ( isset( $my_query_array['paged'] ) && !empty( $my_query_array['paged'] ) ) ? $my_query_array['paged'] : 0;
1
  • Static front pages use page, not paged. Please check the other answer Jul 20, 2015 at 4:24

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.