Forums Forums Search & Filter Pro Custom Post Type AJAX Pagination – Very Close to working !

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #97969

    Hello, and thank you for the great plugin. We’ve spent some time customizing things and believe that we’re very close to having things buttoned up.

    The one snag that I’m not able to get around is getting our numbered pagination to work quite right, although it is very close. When the page loads, the paginated menu exists and all of the links work correctly. But upon refresh, the paginated menu is not being updated with the “current” menu item and updated links/etc. I scoured the forum and tried a number of different approaches, but am now reaching out for a bit of support to see what I have missed.

    Here’s the dev page that we’d like to AJAX paginate:

    [redacted]

    Here’s our function that draws the pagination:

    // Output AJAX Navigation With Bootstrap Markup
    function ajax_page_navi() {
        global $the_query;
        $big = 999999999; // need an unlikely integer
        $pages = paginate_links( array(
            'base' 		   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format'       => '?sf_paged=%#%',
            'current'      => max( 1, get_query_var('paged') ),
            'total'        => $the_query->max_num_pages,
            'prev_next'    => false,
            'type'  	   => 'array',
            'prev_next'    => TRUE,
    		'prev_text'    => __('<i class="fa fa-lg fa-angle-left"></i> <span>Prev</span>'),
    		'next_text'    => __('<span>Next</span> <i class="fa fa-lg fa-angle-right"></i>'),
        ) );
        if( is_array( $pages ) ) {
        	
            $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
            
            echo '<ul class="pagination">';
            foreach ( $pages as $page ) {
                    echo "<li>$page</li>";
            }
           echo '</ul>';
        }
    } /* end page navi */

    Then, we’re using a custom page template (page-recipes.php) to do our custom post type query:

    <?php
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    					
    // loop arguments
    $arr = array( 
    'post_type' => 'recipe', 
    'paged' => $paged,
    'search_filter_id' => 1664
    ); 
    						
    global $the_query;
    $the_query = new WP_Query( $arr ); 
    ?>

    Any ideas about what I might be overlooking here?

    Thanks in advance,

    Ross

    Anonymous
    #97972
    This reply has been marked as private.
    Anonymous
    #97989

    Okay…might have cracked it myself. For anyone reading, it appears that perhaps your pagination navigation code must also live inside the parent DOM element where your query resides, in the case of a custom page/post loop.

    Anonymous
    #97993

    Oh…and I updated our page navigation as follows, note the ‘current’ value:

    // Output AJAX Navigation With Bootstrap Markup
    function ajax_page_navi() {
        global $the_query;
        $big = 999999999; // need an unlikely integer
        $pages = paginate_links( array(
            'base' 		   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
            'format'       => '?sf_paged=%#%',
            'current'      => max( 1, $the_query->query_vars['paged'] ),
            'total'        => $the_query->max_num_pages,
            'prev_next'    => false,
            'type'  	   => 'array',
            'prev_next'    => TRUE,
    	'prev_text'    => __('<i class="fa fa-lg fa-angle-left"></i> <span>Prev</span>'),
    	'next_text'    => __('<span>Next</span> <i class="fa fa-lg fa-angle-right"></i>'),
        ) );
        if( is_array( $pages ) ) {
        	
            $paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
            
            echo '<ul class="pagination">';
            foreach ( $pages as $page ) {
                    echo "<li>$page</li>";
            }
           echo '</ul>';
        }
    } /* end page navi */
    Trevor
    #98054

    Hi Ross

    You resolved this already?

    Anonymous
    #98060

    Hello…yes, I believe we found a solution that will work. For future reference, does my explanation for what I changed sound like a good way to go?

    I’m stumped as to why this works:

    'current' => max( 1, $the_query->query_vars['paged'] ),'

    But this doesn’t:

    'current' => max( 1, get_query_var('paged') ),

    Any thoughts?

    Anonymous
    #98062
    This reply has been marked as private.
    Trevor
    #98081

    I am sure it would make sense to Ross, but not me. I will close this for now then.

    Ross Moderator
    #98305

    Yup makes sense.

    Basically all the examples in the codex use:

    'current' => max( 1, get_query_var('paged') ),

    I think this is actually wrong for many scenarios.

    get_query_var get the global paged var, but depending on how you use S&F (and WP, ie doing a custom query, with pagination), you will need to use

    'current' => max( 1, $the_query->query_vars['paged'] ),' – this get the current value from the query, not the global value

    To explain a little more.

    If you are creating a custom query on and individual page, the global paged var will always be 1. Because the global query is the request to get that page.

    Then you have the custom query, which of course has a different value. I would advise (and planned to submit to the codex) to always get the current page var from the query.

    If its a global query, why not still use global $wp_query and then use the same coding style.

    Anyway, hope that clarifies a little bit.

    Best

Viewing 9 posts - 1 through 9 (of 9 total)