Using wp_pagenavi for pagination with AJAX loaded content but getting links based on wp-admin/admin-

In crunch time with something and I really need some help. I have a custom template page that has some tabs that dynamically load some ajax content, works great. But the wp_pagenavi() properly displays when needed but does not function properly, I believe because the ?paged=# that is being added to the wrong url.

Rather than I’m getting because I used wordpress’s ajax when loading that content.

Thanks for any help you can provide I’m leaving town for a bit and need this fixed before I go so please be quick. Thanks again


  • Div Truth
    • Design Lord, Child of Thor

    Attempting to resolve this myself again I’ve got this figured out so far. Since the content needs to load in the content div again I was wrong to think I could just change the link, I figured that out and that simply loaded the correct data on a new page. The correct approach is to remove the href from the populated wp_pagenav anchors and then run an onclick method which I’ve begun like this:

    function fixPagination(nonce,category,post,content){
    jQuery("#wp-pagenavi_ .wp-pagenavi a").each(function(){
    // jQuery(this).attr('href',jQuery(this).attr('href').replace("/wp-admin/admin-ajax.php?paged=","/category/tv/companies/page/"));
    //answer to original question

    jQuery("#wp-pagenavi_ .wp-pagenavi a").click( function() {
    opacity: 0,
    marginLeft: '-=5'

    // This is what is braking the page right now
    dataType : "html",
    url : "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
    data : {action: "get_tv_content", nonce: nonce, content: content, post: post, category: category },
    success: function(response) {
    opacity: 1,
    marginLeft: '+=5'
    jQuery("#content #social-sidebar-container").animate({
    marginLeft: '-=5'
    error: function(xhr, textStatus, errorThrown){
    alert(errorThrown+"("+xhr+"): " +textStatus);

    If I remove the ajax call made there then everything runs as expected, but as soon as I start that ajax call the entire page freezes and then breaks. Any thoughts would really help I’m running out of other options.

    FYI: action = get_tv_content that is because in this same file I have this defined

    add_action("wp_ajax_".$_REQUEST['action'], $_REQUEST['action']);
    add_action("wp_ajax_nopriv_".$_REQUEST['action'], $_REQUEST['action']);

    function get_tv_content(){}

  • Barry
    • DEV MAN’s Mascot

    wp_pagenavi will grab the page that it is running on and use that as the base for the permalinks, as you are finding out.

    If you want to use that function, rather than write your own, then you’ll need to edit it to accept a variable / $_GET of the base or page to use as the start of your url, and then update your ajax call to pass over the base or page you are calling from.

    It’s not going to be the easiest of things to do, as the plugin looks quite a bit more complex than I’d have expected it to be :slight_smile:

    Maybe this will provide some help:

  • Div Truth
    • Design Lord, Child of Thor

    Sorry I got pulled off this task for a bit because I was hitting a dead end. For a temporal solution we made the pagination area a link to the actual page 1 or 2 rather then deal with the ajax at the moment. I will be coming back to this though and I’ll be sure to try your suggestion there Barry so thank you.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.