• So I found some inconsistance in my expectations and I would like to clear that :).

    I have the fallowing snippet for pagination:

    if ( ! function_exists( 'wpf_pagination' ) ) {
    	function wpf_pagination() {
    		global $wp_query;
    		$big = 999999999; // This needs to be an unlikely integer
    
    		// For more options and info view the docs for paginate_links()
    		// http://codex.wordpress.org/Function_Reference/paginate_links
    		$paginate_links = paginate_links( array(
    			'base'      => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
    			'current'   => max( 1, get_query_var( 'paged' ) ),
    			'total'     => $wp_query->max_num_pages,
    			'end_size'  => 2,
    			'mid_size'  => 5,
    			'prev_next' => True,
    			'prev_text' => __( '« Previous', 'wpf' ),
    			'next_text' => __( 'Next »', 'wpf' ),
    			'type'      => 'list',
    		) );
    
    		// Display the pagination if more than one page is found
    		if ( $paginate_links ) {
    			echo '<div class="pagination">';
    			echo $paginate_links;
    			echo '</div>';
    		}
    	} // end wpf_pagination()
    }

    I want to remove the global $wp_query and replace $wp_query->max_num_pages with get_query_var( 'max_num_pages' ). The problem now is that it doenst return anything?

    When I add the fallowing after global $wp_query:

    echo get_query_var( 'max_num_pages' );
    		echo '<br>||';
    		echo $wp_query->max_num_pages;

    Then I will see:
    ||2

    I have looked at the source at http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/query.php and I cant see why it doesn’t give me the same result?

    So who can tell me what I am missing?

Viewing 1 replies (of 1 total)
  • Thread Starter MekZii

    (@mekzii)

    So no one knows and can help me out why get_query_var( ‘max_num_pages’ ); doesnt get me the same result as $wp_query->max_num_pages;.

Viewing 1 replies (of 1 total)
  • The topic ‘[global $wp_query and get_query_var()] Don't return the same values’ is closed to new replies.