• Resolved brveljkovic

    (@brveljkovic)


    hi all,
    I need help with custom pagination function. I am trying to use max page number value from outside a function as a global variable. Check the code below. Have no idea why I can not make it to work. I have tried lots of stuff.

    so I am trying to pass the value of $number_of_pages from outside the function to $max, which is inside the function.

    /*-----------------------------------------------------------------------------------*/
    $number_of_pages = $query->max_num_pages;
    //echo $number_of_pages;
    /*-----------------------------------------------------------------------------------*/
    /* Numeric Pagination */
    /*-----------------------------------------------------------------------------------*/
    
    	function ct_numeric_pagination_boot() {
    		/**	Add current page to the array */
    		global $number_of_pages;
    		//$paged = get_query_var('page') ? absint( get_query_var('page') ) : 1;
    		$paged = $query->query['paged'];
    		$max = $number_of_pages;
                    .......

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You also need to use global $number_of_pages; outside of your function. Globals need to be declared in each local namespace where the variable is used.

    You’re also using $query->query['paged'] but I don’t see anywhere that establishes $query as an object. FYI, you can get the current query object from global $wp_query. Before using the global query, verify that $wp_query->is_main_query().

    Thread Starter brveljkovic

    (@brveljkovic)

    thanks for reply. At the end I solved it by not using the function, just outputted the code itself directly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Pagination, using global variable value inside a function’ is closed to new replies.