Support » Plugin: Custom Post Type UI » Problem with Pagination for Custom Post Types

  • Resolved cirtoska


    I have seen many had problems with pagination for Custom Post Types and most of them have successfully solved their issue. I still have no luck in that.

    Here is my problem.

    I’m using Custom Post Type UI for creating Custom Post types ( for example one of the post types that I’ve created is articles ).
    For listing them I have created Page Template articles.php and the slug that I’m using for that page is article ( for example the page where I have created is listed here ).

    The first page is listing fine, but when I go to the next page it redirect to the first page and gives the permalink of the second page

    I’m using Maxx – Responsive Creative WordPress Theme and the code for the pagination for this theme looks like this:

    /*Custom Pagination
    if ( ! function_exists( 'md_pagi_nav' ) ) :
    	function md_pagi_nav(array $query = array()) {
    	<div class="m-pagination">
                    global $wp_query;
                    $big = 999999999; 
                    echo paginate_links( array(
                        'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
                        'format' => '?paged=%#%',
                        'current' => max( 1, get_query_var('paged') ),
                        'total' => $wp_query->max_num_pages,
                        'next_text'    => __('Next →','framework'),
                        'prev_text'    => __('← Prev','framework')
                    ) );
                <span class="pagination-meta">
                        //display Page x of y pages
                        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                        echo 'Page ' . $paged . ' of ' . $wp_query->max_num_pages ;

    Can someone with more experience in coding help me how to solve this issue please?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Michael Beckwith


    Still having any issues with this one?


    Plugin Author Michael Beckwith


    You said you’re using a page template for the Custom Post Type display, articles.php. I’m guessing you have something like “Template Name: Articles” at the top in a php comment block, correct? For my reference, if you could pastebin the articles.php file, that’d be awesome.

    What code are you using to display the post type? Grabbing the global $wp_query variable on a page is going to pull the variable for the page’s query, not the post type’s

    That’s my first set of questions, I’ll be able to help a bit better after that.

    Thanks for your feedback Michael,

    1. Yes. I’m using “Template Name: Articles”, here is a pastebin for articles.php

    2. The code that I’m using for displaying the post type
    <?php query_posts( 'post_type=articles'); ?>

    Plugin Author Michael Beckwith


    I’d honestly start by using one of the template files indicated here:

    There are dedicated template file names for custom post types, specifically archive-$cpt_name.php

    Once you have that part in place, I’d see how far along you are with the removal of your query_posts() attempt, which is not a good way to try and achieve this, for performance reasons among others.

    Thank you Michael for your support.

    I found the solution! I have created as you suggested archive-articles.php and instead <?php query_posts( 'post_type=articles'); ?> I replaced it with

    <?php function articles_filter($query) {
      if ( !is_admin() && $query->is_main_query() ) {
        if (is_page_template('archive-articles.php')) {
          $query->set('post_type', 'articles');
    add_action('pre_get_posts','articles_filter'); ?>

    Now the navigation works!


    Plugin Author Michael Beckwith


    Awesome to hear. Shouldn’t have need for that pre_get_posts filter logically, but I’m not going to argue against something working at this point.

    Well if you have any other suggestion we can try it also. I’m willing to try everything for better performance of my custom post types.

    Also I have another suggestion: In Advanced Options for Custom Post Types the attribute Has Archive is by default False. If people use archive-$cpt_name.php for displaying custom post types they should manually change this option to True.

    Plugin Author Michael Beckwith


    I don’t believe “has_archive” actually has any effect on the template hierarchy. A bit confusing in the end because of that, but archive-$cpt.php is first in line for CPTs regardless of what features its registered with.

    No “has-archive” doesn’t have any effect on the template hierarchy. I was mentioning that “has_archive” should be by default “True”, not “False” for it to display archive from the custom post type.

    Anyway thanks again for your time

    Best Regards,
    Aleksandra 🙂

    Plugin Author Michael Beckwith


    I think I get what you mean now. It’s been a tired day.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Problem with Pagination for Custom Post Types’ is closed to new replies.