WordPress.org

Ready to get started?Download WordPress

Forums

404 pagination error with custom post type (3 posts)

  1. Pulsar_Media
    Member
    Posted 1 year ago #

    I am currently developing a custom theme for a client and i have a custom post type that i created called Press Releases. I am loading the Press release posts on a template page labelled template-press.php. Inside this template i am running a WP_Query to fetch my press releases and then restoring the query back to the original wordpress query. The problem i am experiencing is the pagination - it keeps throwing a 404 error when i click on the Next Page link.

    The webpage can be viewed here: http://test.inago.com/press/

    I configured wordpress to display 5 posts at a time and there a total of 10 Press Release posts. The first 5 are being displayed followed by the Next Page link but again the Next Page link takes me to a 404 error instead of displaying the next 5 Press Release posts.

    Can anyone shed some light as to why this is happening?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    See: http://codex.wordpress.org/Pagination#Troubleshooting_Broken_Pagination

    What functions are you using for the pagination?

  3. Pulsar_Media
    Member
    Posted 1 year ago #

    Here is the code i am executing in my template file (template-press.php) to retrieve my custom post type posts:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $arguments = array(
    		'post_type' => 'post_press',
    		'post_status' => 'publish',
    		'paged' => $paged
    	);
    
    $press_query = new WP_Query($arguments);
    pm_set_query($press_query);
    
    if ($press_query->have_posts()) : while ($press_query->have_posts()) : $press_query->the_post();
    
    endwhile else :
    'No Posts were found'
    endif
    
    pm_restore_query();

    There are two additional methods i am using that are saved in my functions.php file which are used to save and restore the global $wp_query:

    function pm_set_query($custom_query=null) {
    	global $wp_query, $wp_query_old, $post, $orig_post;
    	$wp_query_old = $wp_query;
    	$wp_query = $custom_query;
    	$orig_post = $post;
    }
    
    function pm_restore_query() {
    	global $wp_query, $wp_query_old, $post, $orig_post;
    	$wp_query = $wp_query_old;
    	$post = $orig_post;
    	setup_postdata($post);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic