Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End AJAXing for Paginated WP Template Part

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #205763
    Alex Zaworski
    Participant

    Hi Friends,

    Let me preface this by saying I’m new to WordPress and newer to AJAX so please forgive any gross misconceptions. Here’s my situation:

    I have a post type called event. By default, on that post type’s archive, I’d like to display all events as a list. I have it capped at 5 events per page and the rest are paginated. Here’s the code I’m using for pagination:

    <?php 
        global $wp_query;
        if ($wp_query->max_num_pages > 1):
     ?>
        <div class="pagination">
            <?php
                echo paginate_links( array(
                    'base' => get_pagenum_link(1) . '%_%',
                    'format' => 'page/%#%',
                    'current' => max( 1, get_query_var('paged') ),
                    'total' => $wp_query->max_num_pages,
                    'end_size' => 1,
                    'mid_size' => 2,
                ) );
                ?>
        </div>
    <?php endif; ?>
    

    The list view is set up as a template part. I’d like to have a button that users can click to swap that template out for a monthly view instead. I was able to get AJAXing for a template part to work okay, but if I then go back to that list view my pagination gets all wonky because the URLs become relative to my AJAX url. Instead of the links being:

    http://my_sitesite/events/page/2

    I get:

    http://my_site/wp-admin/admin-ajax.php?action=ajax_test/page/2

    which is obviously a dead url. What can I do here? Do I need to somehow change my pagination to AJAX everywhere? Is more context needed to answer this (really have no idea, happy to supply any relevant code)?

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.