• Resolved harshclimate

    (@harshclimate)


    Hi all. I’ve tried searching the google and nothing seems to be resolving my issue. Currently, I’m using pagination on home.php. On localhost, the pagination works as it should, but when I uploaded my site to the domain, pagination stopped working as it should. The code on home.php is:

    $currentpage = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array(
    'posts_per_page' => 12,
    'post_type' => array('arizona_wine', 'arizona_beer'),
    'orderby' => 'title',
    'order' => 'ASC',
    'paged' => $currentpage
    );
    $all_posts = new WP_Query($args);

    Then the typical loop with the added variable of $all_posts…

    To call the pagination on my theme, I use the ever-so-used:

    $big = 999999999;
    echo paginate_links(
    array(
    'base' => str_replace($big, '%#%', get_pagenum_link($big)),
    'format' => '?paged=%#%',
    'current' => max(1, get_query_var('paged')),
    'total' => $all_posts -> max_num_pages,
    'prev_text' => ('Previous'), 'next_text' => ('Next'),
    )
    );

    The problem I’m running in to is – on localhost, the pagination page numbers work perfectly. I can click page 2, page 3, page 4 etc and content shows up. When I’m on my actual domain name, this is not working. Content that should be on page/2/ isn’t showing up at all (“Page not found”). The URL says page/2/, but it’s referencing index.php.

    I should note that the posts are from custom post types “arizona_wine, arizona_beer”. I’m not sure how to pose this question without starting here. If more info is needed, I would be 100% willing to give it. Everything else works as designed. Just this one issue.

    • This topic was modified 5 months, 1 week ago by harshclimate.

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Hello @harshclimate
    Please try to update Permalinks.
    Go to Settings > Permalinks in your WordPress dashboard.
    Ensure that a permalink structure is selected (e.g., Post name or a custom structure) . Click “Save Changes” to regenerate rewrite rules, even if you don’t make any changes.

    Thread Starter harshclimate

    (@harshclimate)

    Hi Dipika. Thanks for your response. I have tried that a few times without success. Do you notice anything in the code that might be wrong?

    Moderator bcworkz

    (@bcworkz)

    Hi harshclimate, I can explain why it’s not working, but iunique t’s a mystery to me why it works on localhost. The “paged” query var belongs to the main query, the one for your home page. WP knows that query has only the one page, so querying for page 2 is invalid. You’re using a query var for your custom query that doesn’t belong to you ?? My recommendation is to use your own custom query var for pagination instead of using “paged”.

    Thread Starter harshclimate

    (@harshclimate)

    Hi bc! Long time no “see”! I’m not quite sure what you mean by using my own custom query? My $all_posts variable is referencing the new wp_query. Are you saying that I shouldn’t be using get_query_var? If that’s what you mean, I wouldn’t know how to define my own query…

    I read that if I were using front-page.php I would use ‘page’ instead of ‘paged’ but I’m using home.php

    Thread Starter harshclimate

    (@harshclimate)

    Okay, I added a function

    add_filter(‘query_vars’, ‘registering_custom_query_var’);

    function registering_custom_query_var($query_vars) {
    
        $query_vars[] = 'paginate'; // Change it to your desired name
    
        return $query_vars;
    }

    $currentpage = get_query_var('paginate') ? get_query_var('paginate') : 1;
    $args = array(
    'posts_per_page' => 12,
    'post_type' => array('arizona_wine', 'arizona_beer'),
    'orderby' => 'title',
    'order' => 'ASC',
    'paginate' => $currentpage
    );
    $all_posts = new WP_Query($args);

    Still giving me a “page not found”, I’m assuming I didn’t do it correctly…

    Thread Starter harshclimate

    (@harshclimate)

    It’s just so strange because it’s showing page 2 in the address bar, but there’s no content showing. On localhost, it shows the content :/

    Moderator bcworkz

    (@bcworkz)

    You’re on the right track in using “paginate”, but you meed to alter your paginate_links() parameters so it generates a link similar to https://example.com/?paginate=2 (the version of this with your domain does seem to work correctly, except paginate_links() currently does not currently recognize it’s on page 2)

    If you really want the format like https://example.com/paginate/2/ you’d need to add a rewrite rule that recognizes the “paginate” element and internally rewrites the request to my initial example above.

    Thread Starter harshclimate

    (@harshclimate)

    I’m not at all sure how to write a rewrite rule to do that. I’m not even sure how to make paginate_links recognize the next pages. Is there some documentation you can link me to with examples? I’ll take a look around for some info, though…

    edit -> I did change the areas in paginate_links from paged to paginate but nothing changed as the end result. Now I’m searching around for rewrites, and the snippets I’ve tried don’t seem to help much. Though, I’m not sure what I’m doing with them other than copying and pasting them in to functions. I’ll study them a bit more…

    • This reply was modified 5 months, 1 week ago by harshclimate.
    Thread Starter harshclimate

    (@harshclimate)

    Nothing I’m doing is working. I’ll look around to see if there’s a perfect situation for paginate_links(). Maybe I need to change the CPT’s to categories or something or put everything on the index.php. I dunno. This stuff is too hard for a carpenter like myself.

    Moderator bcworkz

    (@bcworkz)

    Just changing paged to paginate is not enough, as you’ve seen. get_pagenum_link() does not return the URL you want. You may simply supply the desired URL as a static string for the “base” arg, using %#% where the page number should go.

    I suggest first getting the ?paginate=2 version working first. Once you at least have something working you can tackle the rewrite rule for getting /paginate/2/ working if you still have the patience for it. One thing sometimes missed with rewrite rules is forgetting to visit the permalinks settings screen to cause the rewrite rules to be regenerated (no need to save anything, loading the page is enough).

    The other tricky part of rewrite rules is getting the regex correct. This resource can help with that: https:regexr.com

    Thread Starter harshclimate

    (@harshclimate)

    Thanks for the reply. I’ve been running in to strange things during this issue with the website. Like, the caching has been super crazy. I had to contact my host to make sure files were actually uploading because every single time I made an edit and refreshed the permalink structure, nothing would ever change. Also, the content on home.php would disappear once I logged in as admin. When I logged out, the content came back. Totally whack.

    I’ve decided to start from scratch and reorganize. I’m going to remove cpt’s and just use cats and tags. Seems simpler for some reason. I’ll try the same pagination fiasco but hopefully without caching problems.

    I have ACF Pro, the classic editor and Font Awesome pro plugins installed so hopefully those aren’t suspect.

    Thanks, BC. I’ll probably start another topic once I get this clean version finished (pretty close on that already). I’m on slack as Brian but I know I can’t ask questions there ??

    Moderator bcworkz

    (@bcworkz)

    Yeah, you don’t want any caching active when you’re trying to develop custom code. It would indeed be crazy making. Also, the need to repeatedly upload files to the server with every correction, as simple as it may be, still gets to be a PITA. While it may seem like overkill for where you’re at, I still recommend implementing a local version of WP. You can then edit files directly and run with no caching active. You can fully develop and test your code locally first, and only when it’s fully functional upload it to your server. I’ve no experience with Local (one-click installation tool), but I’ve heard from several developers that it’s pretty easy to get up and running with it.

    In any case, if there’s caching in place that’s difficult to temporarily turn off, try some of the “cache busting” techniques you can find through a general internet search. Sometimes simply adding a nonsense query string to the URL will let you bypass caching.

    Thread Starter harshclimate

    (@harshclimate)

    Heya BC. Yeah, I usually work in localhost but for some reason I was caught up on the web server since I was updating at the same time. I get my channels crossed when I have too much going on. Plus, font awesome didn’t work on my local environment for some reason. I guess I wanted those to show up more than anything else for some reason ??

    Anyway, I’m good for now. Decided to just rework things a bit since I couldn’t get it working. I like what I ended up with so it’s all good.

    Thanks for the time, mister.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.