WordPress.org

Ready to get started?Download WordPress

Forums

Give a 404 page when pagination of custom type post in 3.4.1 (4 posts)

  1. wpxp
    Member
    Posted 1 year ago #

    The index.php is to show custom post type-'products', The code is as following.

    $wp_query = new WP_Query();
    $wp_query->query('post_type=products&paged='.$paged);
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ......

    It works well in WordPress 3.3.2.but it goes wrong in 3.4.1.
    URL like: http://xxx.com/?paged=1 or http://xxx.com/, it is OK;
    URL like: http://xxx.com/?paged=2, it gives a 404 page.
    If 404.php file is removed from theme folder,
    Enter http://xxx.com/?paged=2, it shows posts, but the page title is 'Page not found'

    How to fix it? Thanks

  2. cynnie88
    Member
    Posted 1 year ago #

  3. keesiemeijer
    moderator
    Posted 1 year ago #

    If this is on the home page (index.php), you can try it without the query and with this in your theme's functions.php:

    function my_post_queries( $query ) {
      // not an admin page and is the main query
      if (!is_admin() && $query->is_main_query()){
        if(is_home()){
          $query->set('post_type', array('products'));
        }
      }
    }
    add_action( 'pre_get_posts', 'my_post_queries' );

    http://developer.wordpress.com/2012/05/14/querying-posts-without-query_posts/
    http://www.billerickson.net/customize-the-wordpress-query/

  4. wpxp
    Member
    Posted 1 year ago #

    Resolved!thanks,keesiemeijer

Topic Closed

This topic has been closed to new replies.

About this Topic