WordPress.org

Forums

[resolved] Pagination on custom post_type (4 posts)

  1. pybiru
    Member
    Posted 2 years ago #

    Hi,

    I am using WordPress3.5.1 + Magic Fields plugin(v2.1). Everything works great, except I can't seem to get the pagination working. My URL(courses is the post_type) looks like this "http://mysite.com/courses/". When I click the "next" pagination link it changes the URL to "http://mysite.com/courses/page/2/" and takes me to a 404 page. Has anyone come accross this issue before? My pagination code looks like this...

    <?php
    
    		    $start = max(1, $paged - 4);
    		    $end = min ( $loop->max_num_pages, $paged + 4);
    
    		    if( $paged > 1) { ?>
    		        <a href="<?php echo get_pagenum_link($paged-1);?>"><</a>
    		    <?php }
    
    		    for($i = $start; $i <= $end; $i++) { ?>
    		        <a href="<?php echo get_pagenum_link($i);?>" <?php echo ($paged==$i)? 'class="active"':'';?>><?php echo $i;?></a>
    		    <?php }
    
    		    if($paged != $loop->max_num_pages ) { ?>
    		    	<a href="<?php echo get_pagenum_link($paged+1);?>">></a>
    	    	<?php } ?>
  2. keesiemeijer
    moderator
    Posted 2 years ago #

    Did you register the post type (with the plugin?) with: 'has_archive' => true, ?
    http://codex.wordpress.org/Function_Reference/register_post_type

    On what template file are you trying this?
    http://codex.wordpress.org/Template_Hierarchy#Custom_Post_Types_display

    Why not use the WordPress navigation functions?
    http://codex.wordpress.org/Pagination#Function_Reference

    Do you have a query on the loop?
    http://codex.wordpress.org/Function_Reference/WP_Query
    http://codex.wordpress.org/Function_Reference/query_posts

    Do you have a page or a custom taxonomy that have the same title "courses"?

  3. pybiru
    Member
    Posted 2 years ago #

    Thanks for reply keesiemeijer.

    Your first link did the trick, I have it working now. In Magic Fields plugin, I could click "Magic Fields -> Edit Post Type" and then tick a box for "has archive" and under that "archive slug" I entered "courses"(my custom post_type) and it works now.

    Thanks a million.

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    No problem :-)
    I'm glad you've got it resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic