• Hi All,
    Apologies if this has been asked before, but hours of googling have produced nothing.
    I have a custom query with pagination on a single.php page. The exact same code is working in my category.php. The pagination is printing properly and the links printing correctly. My permalinks setting is /%category%/%postname%, so a default URL will look like mysite.com/news/news-article. The previous_posts_link() is printing out the proper URL as mysite.com/news/news-article/page/2. Once I hit that link, the Net tab in Firefox shows that the URL /news/news-article/page/2 has been 301 redirected to /news/news-article, so the pagination is never updated. The default posts per page is set to 1 and the posts_per_page in my query has been set to 5. My .htaccess is as follows, automatically set up by WordPress – I haven’t touched it.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress

    Anybody seen anything like this before and have any idea how to fix it? I’d really hate to have to write my own paging functions when WP has such functionality built in, but I’m afraid I may have to.
    Please help save what little hair I have left!
    Thanks much,
    Garrett

Viewing 9 replies - 1 through 9 (of 9 total)
  • Are you using the wp_link_pages function?

    I’ve previously had to copy this function from the core into my functions.php and play around with it, changing the name of course. In order to get it to play nice.

    I’m not sure why you’re using ‘previous_posts_link()’ though.

    Could you put the snippet of your single.php up here, or possibly on pastebin if it’s quite long?

    Thread Starter gratrockstar

    (@gratrockstar)

    I am using previous_posts_link and next_posts_link because I am trying to paginate a list of posts, not the post itself. Sorry if that wasn’t clear.
    Here is the pastebin showing the code that works properly on a category.php page and not on a single.php page.
    https://pastebin.com/kGSEaN0U
    As noted, the links print properly as faqs/faq-title/page/2 but after clicking, it is being 301 redirected to faqs/faq-title. My permalinks are using /%category%/%postname%.
    category.php is working properly – /category/faqs/page/2 is showing the second page of post titles and not redirecting.
    Anybody have any ideas?
    Thanks!
    Garrett

    You ever get this figured out?

    It’s strange, it works for me on 2 local builds, but doesn’t on another local build and/or a development server build… very strange…

    –d

    Thread Starter gratrockstar

    (@gratrockstar)

    Nope, I ended up having to write some custom paging functions.
    From what little bit I found online, it’s not possible on single pages, so I went with the custom option. Hope this helps someone else someday!
    Garrett

    so you were able to custom paginate? how did you customize it? maybe a code snippet example?

    this is bugging me.

    so you were able to custom paginate? how did you customize it? maybe a code snippet example?

    this is bugging me.

    adding to this… I noticed it was working locally when the port wasn’t the default 80… so anything like localhost:8080 was working fine…

    … not sure if that helps anyone…

    –d

    Here’s a fix… I didn’t figure it out, but I thought I would share…

    add_filter(‘redirect_canonical’,’pif_disable_redirect_canonical’);

    function pif_disable_redirect_canonical($redirect_url) {
    if (is_singular(‘pov_channel’)) $redirect_url = false;
    return $redirect_url;
    }

    WOOT!

    –d

    Awesome work whatadewitt! For those looking for a more detailed explanation of what’s going on I wrote a post about it https://wp.me/p1F7Tn-1a.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Pagination on single.php causing 301 redirect’ is closed to new replies.