Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4024532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:44:00+00:00 2026-05-20T10:44:00+00:00

I have a similar problem with this ( https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination ) and can’t really figure

  • 0

I have a similar problem with this ( https://wordpress.stackexchange.com/questions/9593/custom-post-type-archive-with-pagination ) and can’t really figure out what to do !

I have a custom post type name ‘gallery’ and I have created a template to show all ‘gallery’ items. The url is http://www.domain.com/gallery. I use WP_Pagenavi plugin. Whenever I try to go to page 2 or higher, the url becomes http://www.domain.com/gallery/page/2 and it returns a 404 page. I read everywhere about it and I guess it has something to do with rewrite rules, the query and whatever else!

I have tried adding

add_rewrite_rule( 'gallery/page/([0-9]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );

The thing is that I don’t want to change my permalinks structure which now is /%postname%/.

Here is my full code

        <?php

        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'post_type' => 'gallery',
            'paged' => $paged,
            'showposts' =>24
            ); query_posts($args);

        if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>


                ...stuff here...

                <?php endwhile; endif; ?>


        <?php 
            wp_pagenavi( );
        ?>

and here is my functions.php code for the gallery

add_action('init', gallery);
function gallery() {
$args = array(
        'label' => __('Gallery'),
        'singular_label' => __(Gallery),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => true,
        'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')        
);

register_post_type( 'gallery' , $args );
add_rewrite_rule( 'gallery/page/([0-9]+)/?$', 'index.php?pagename=gallery&paged=$matches[1]', 'top' );
}

I am pulling my hair with this (grrrrr).
Thank you in advance !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:44:00+00:00Added an answer on May 20, 2026 at 10:44 am

    Your issue is the permalink structure. /%postname%/ is a terrible structure because of how it hits the database. You’ll always have troubles with custom post types and custom taxonomies if your not including /%category%/ in your permalink structure. I just always use /%year%/%category%/%postname%/

    If you insist on the permalink structure above then this should fix your issue.

    add_rewrite_rule('projects/page/([0-9]+)/?$', 'index.php?pagename=projects&paged=$matches[1]', 'top');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem similar to [this question][1] https://stackoverflow.com/questions/1449072/debugging-problem-in-x-code-iphone-development I have created an application,
I have a similar problem to this post . I need to display up
I have a problem very similar to the one described here: https://microsoft.public.win32.programmer.kernel.narkive.com/Ly2P8Yp2/prevent-vista-from-marking-my-application-as-non-responding That thread
I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
Similar to this question: link However I have already mastered that. My problem is
My problem is similar to Django Passing Custom Form Parameters to Formset Ive have
I've done extensive research on this, and am baffled. Similar questions on stackoverflow have
I have looked everywhere but have not found a problem similar to this. I
I seem to have exactly the same problem as this person: http://forums.adobe.com/thread/618752 He also
I thought this other SO thread would have answered my question (http://stackoverflow.com/questions/4883751/trouble-reading-json-object-in-python), as it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.