• festsoft

    (@festsoft)


    I am trying to debug a pagination error. I am using a theme with a custom post-type=’job’ and I am trying to show a paginated list of the ‘job’ posts using WordPress next_post_link etc. There seems to be a curious link between the number of published post-type=’post’ and the pagination of post-type=’job’. Using exactly the same code apart from post-type=’job’ or post-type=’post’ the ‘posts’ always paginate correctly. When changing to post-type=’job’ the ‘jobs’ paginate correctly if the number of published ‘posts’ takes as many pages or more than the pages of ‘jobs’. But if there are fewer pages of publihed ‘posts’ the last page of ‘jobs’ is not shown – I get a 404 Not Found instead. Any help or suggestions appreciated – I have been days on this issue!

    <?php
    if(get_query_var('paged')) {
        $paged = get_query_var('paged');
    } elseif(get_query_var('page')) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    $alm_args = array(
        'post_type' => array('job'), //'job' is a custom post-type
        'paged' =>  $paged,
    );
    $alm_query = new WP_Query($alm_args);
    if ($alm_query->have_posts()) :
        while ($alm_query->have_posts()) :
            $alm_query->the_post();
    ?>	
    
    [POST DISPLAY]
    
    <?php
        endwhile;
        next_posts_link('&laquo; Next page', $alm_query->max_num_pages)
        previous_posts_link('Previous page &raquo;')
    endif;
    wp_reset_postdata();
    ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Looks good to me.

    Can you post the full code from the theme template.

    Thread Starter festsoft

    (@festsoft)

    The code below is modified from the theme template by my attempts to debug. The problem is the same whether or on the SUBMENU section is there.

    <?php
    /*
    	Template Name: Jobs
    */
    //Modified for custom query with WP pagination
    get_header();
    ?>
    		<div id="content">
    <!-- SUBMENU CODE START -->
    			<div class="up_taxbar">
    <h3>&nbsp; &nbsp; FILTER JOB TYPES </h3>
    			</div>
    			<div class="taxbar">
    <?php
    $taxonomy     = 'job_type';
    $orderby      = 'name';
    $show_count   = 0;      // 1 for yes, 0 for no
    $pad_counts   = 0;      // 1 for yes, 0 for no
    $hierarchical = 1;      // 1 for yes, 0 for no
    $title        = '';
    
    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title
    );
    ?>
    <ul>
    <li><a href="http://www.acasalamunca.ro/?cat=0">ALL</a></li>
    <?php wp_list_categories( $args ); ?>
    </ul>
    			</div>
    
    			<div class="up_taxbar">
    <h3>&nbsp; &nbsp; LATEST JOBS</h3>
    			</div>
    <!-- SUBMENU CODE ENDS --> 
    
    <?php $count = 0; ?>
    
    <?php
    //Recommended
    if(get_query_var('paged')) {
        $paged = get_query_var('paged');
    } elseif(get_query_var('page')) {
        $paged = get_query_var('page');
    } else {
        $paged = 1;
    }
    $alm_args = array(
        'post_type' => array('job'),
        'paged' =>  $paged,
    );
    
    $alm_query = new WP_Query($alm_args);
    
    if ($alm_query->have_posts()) :          
    
        while ($alm_query->have_posts()) :
            $alm_query->the_post();
    ?>
    			<div class="box clearfix <?php if (++$count % 2 == 0) { echo "altbox"; } ?>" id="post-<?php the_ID(); ?>">
    				<div class="btitle">
    					<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
    						<?php echo short_title('...', 7);  ?></a></h2>
        				<p><?php $comdes=get_post_meta($post->ID, 'wtf_comdescript', true); echo $comdes; ?></p>
    					<?php echo alm_job_type_tag($post->ID); //See plugins/alm_bidcontrol/alm_bidcontrol.php ?>
    				</div>
    				<div class="jlocation"> <?php $loc=get_post_meta($post->ID, 'wtf_comlocate', true); echo $loc; ?></div>
    				<div class="jpostime"><?php echo alm_format_bid_duedate($post->ID); ?></div>
    			</div>
    <?php
        endwhile;
    ?>
    			<div class="clear"></div>            
    
    <?php //wp_pagenavi(array('query'=>$alm_query)); ?>
    <div id="navigation" class="clearfix" style="width:300px;">
        <p>MONITOR: Page = <?php echo $paged; ?> Max number of pages = <?php echo $alm_query->max_num_pages; ?></p>
            <div style="float:left;"><?php next_posts_link('&laquo; Next page', $alm_query->max_num_pages) ?></div>
            <div style="float:right;"><?php previous_posts_link('Previous page &raquo;') ?></div>
            <div class="clear"></div>
    
    </div>
    
    <?php
    else :
    ?>
    			<h1 class="title">No Data</h1>
    			<p>Sorry, but there is no data for this page.</p>
    <?php
    endif;
    wp_reset_postdata();
    ?>
    		</div> <!-- content -->
    <?php
    get_sidebar();
    get_footer();
    ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    Still looks good to me.

    Can you put this just after the $alm_query and post the output here.

    <?php
    echo '<pre>';
    print_r($alm_query);
    echo '</pre>';
    ?>

    Moderator keesiemeijer

    (@keesiemeijer)

    Also setting the ‘posts_per_page’ parameter might help:

    $alm_args = array(
        'post_type' => array('job'),
        'paged' =>  $paged,
        'posts_per_page' => 10,
    );

    Thread Starter festsoft

    (@festsoft)

    I included posts_per_page=10 and get the following behaviour:
    The 14 published jobs are displayed as 10 and 4 as expected IF the number of published ‘posts’ is 6 or more, but for 4 or 5 published ‘posts’ the 14 ‘jobs’ are displayed as 10 and ‘Not found’.
    The Settings>Reading max blog pages was set to 5.
    In pseudo code it seems that my observations are represented by

    no_of_job_pages = 1+int(14/10) = 2
    no_of_'post'_pages = 1+int(no_of_published_posts/max_blog_pages)
    if(no_of_'post'_pages>=no_of_job_pages)
    then job_posts_pagination_works
    else last_page_of_jobs = 404_Not_found

    I tested that by increasing max_blog_pages to 6 and result was consistent.

    This is the output of print_r($alm_query)

    WP_Query Object
    (
        [query_vars] => Array
            (
                [post_type] => Array
                    (
                        [0] => job
                    )
    
                [paged] => 1
                [posts_per_page] => 10
                [error] =>
                [m] =>
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [name] =>
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] =>
                [author] =>
                [author_name] =>
                [feed] =>
                [tb] =>
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [fields] =>
                [menu_order] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
                [post_parent__in] => Array
                    (
                    )
    
                [post_parent__not_in] => Array
                    (
                    )
    
                [author__in] => Array
                    (
                    )
    
                [author__not_in] => Array
                    (
                    )
    
                [ignore_sticky_posts] =>
                [suppress_filters] =>
                [cache_results] => 1
                [update_post_term_cache] => 1
                [update_post_meta_cache] => 1
                [nopaging] =>
                [comments_per_page] => 50
                [no_found_rows] =>
                [order] => DESC
            )
    
        [tax_query] => WP_Tax_Query Object
            (
                [queries] => Array
                    (
                    )
    
                [relation] => AND
            )
    
        [meta_query] => WP_Meta_Query Object
            (
                [queries] => Array
                    (
                    )
    
                [relation] =>
            )
    
        [date_query] =>
        [post_count] => 10
        [current_post] => -1
        [in_the_loop] =>
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 14
        [max_num_pages] => 2
        [max_num_comment_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] =>
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] => 1
        [is_404] =>
        [is_comments_popup] =>
        [is_paged] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] =>
        [is_robots] =>
        [is_posts_page] =>
        [is_post_type_archive] =>
        [query_vars_hash] => d610dd622800e9450b4322d2c1f2a8ed
        [query_vars_changed] =>
        [thumbnails_cached] =>
        [stopwords:WP_Query:private] =>
        [query] => Array
            (
                [post_type] => Array
                    (
                        [0] => job
                    )
    
                [paged] => 1
                [posts_per_page] => 10
            )
    
        [request] => SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'job' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10
        [posts] => Array
            (
                [0] => WP_Post Object
                    (
                        [ID] => 280
                        [post_author] => 3
                        [post_date] => 2014-03-30 06:57:02
                        [post_date_gmt] => 2014-03-30 06:57:02
                        [post_content] =>
                        [post_title] => Another Job
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => another-job
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=280
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [1] => WP_Post Object
                    (
                        [ID] => 255
                        [post_author] => 3
                        [post_date] => 2014-03-24 17:01:31
                        [post_date_gmt] => 2014-03-24 17:01:31
                        [post_content] =>
                        [post_title] => TEST Job #30
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => test-job-30
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=255
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [2] => WP_Post Object
                    (
                        [ID] => 254
                        [post_author] => 3
                        [post_date] => 2014-03-24 17:00:54
                        [post_date_gmt] => 2014-03-24 17:00:54
                        [post_content] =>
                        [post_title] => Test Job #29
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => test-job-29
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=254
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [3] => WP_Post Object
                    (
                        [ID] => 253
                        [post_author] => 3
                        [post_date] => 2014-03-24 16:58:57
                        [post_date_gmt] => 2014-03-24 16:58:57
                        [post_content] => Pagination test
                        [post_title] => Test Job #27
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => test-job-27
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=253
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [4] => WP_Post Object
                    (
                        [ID] => 252
                        [post_author] => 3
                        [post_date] => 2014-03-24 16:56:28
                        [post_date_gmt] => 2014-03-24 16:56:28
                        [post_content] => Testing pagination
                        [post_title] => Test Job #26
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => test-job-26
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=252
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [5] => WP_Post Object
                    (
                        [ID] => 239
                        [post_author] => 3
                        [post_date] => 2014-03-22 20:46:51
                        [post_date_gmt] => 2014-03-22 20:46:51
                        [post_content] => Urgently needed
                        [post_title] => Pagination expert
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => pagination-expert
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=239
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [6] => WP_Post Object
                    (
                        [ID] => 235
                        [post_author] => 1
                        [post_date] => 2014-03-09 02:50:02
                        [post_date_gmt] => 2014-03-09 02:50:02
                        [post_content] => Just adding some more jobs
                        [post_title] => Test job #25
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => test-job-25
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-03-31 11:00:54
                        [post_modified_gmt] => 2014-03-31 11:00:54
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=235
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [7] => WP_Post Object
                    (
                        [ID] => 234
                        [post_author] => 1
                        [post_date] => 2014-03-09 02:49:11
                        [post_date_gmt] => 2014-03-09 02:49:11
                        [post_content] => Just adding some more jobs
                        [post_title] => Test job #24
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => test-job-24
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-04-01 10:23:38
                        [post_modified_gmt] => 2014-04-01 10:23:38
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=234
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [8] => WP_Post Object
                    (
                        [ID] => 233
                        [post_author] => 1
                        [post_date] => 2014-03-09 02:48:46
                        [post_date_gmt] => 2014-03-09 02:48:46
                        [post_content] => Just adding some more jobs
                        [post_title] => Test job #23
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => test-job-23
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-04-01 10:23:38
                        [post_modified_gmt] => 2014-04-01 10:23:38
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=233
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
                [9] => WP_Post Object
                    (
                        [ID] => 232
                        [post_author] => 1
                        [post_date] => 2014-03-09 02:48:01
                        [post_date_gmt] => 2014-03-09 02:48:01
                        [post_content] => Just adding some more jobs
                        [post_title] => Test job #22
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => open
                        [ping_status] => open
                        [post_password] =>
                        [post_name] => test-job-22
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2014-04-01 10:23:38
                        [post_modified_gmt] => 2014-04-01 10:23:38
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://localhost/alm/?post_type=job&p=232
                        [menu_order] => 0
                        [post_type] => job
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
    
            )
    
        [post] => WP_Post Object
            (
                [ID] => 280
                [post_author] => 3
                [post_date] => 2014-03-30 06:57:02
                [post_date_gmt] => 2014-03-30 06:57:02
                [post_content] =>
                [post_title] => Another Job
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => open
                [ping_status] => open
                [post_password] =>
                [post_name] => another-job
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2014-03-31 11:00:54
                [post_modified_gmt] => 2014-03-31 11:00:54
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => http://localhost/alm/?post_type=job&p=280
                [menu_order] => 0
                [post_type] => job
                [post_mime_type] =>
                [comment_count] => 0
                [filter] => raw
            )
    )

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Incomplete pagination of custom post list depends on nuber of 'normal posts'’ is closed to new replies.