Skip to:
Content
Pages
Categories
Search
Top
Bottom

pagination in custom query


  • divyesh25
    Participant

    @divyesh25

    Hi Everyone,

    i am make one function in function.php file in which i wrote my own query. now i want set pagination(bbpress pagination). i dont know about and any idea. please help me . below my function.

    function best_conversationstarters(){
    	global $wpdb, $paged, $max_num_pages;
    
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $post_per_page = (intval(get_query_var('posts_per_page'))>0) ? intval(get_query_var('posts_per_page')) : 5;
        $offset =  ($paged - 1)*$post_per_page;
    	
    	$best_conversation_starter =  "SELECT COUNT(*) topic, post_author FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type LIKE '%topic%' GROUP BY post_author ORDER BY topic DESC LIMIT ".$offset.", ".$post_per_page;
    	$sql_result = $wpdb->get_results( $best_conversation_starter, OBJECT);
    	
    	/* Determine the total of results found to calculate the max_num_pages
         for next_posts_link navigation */
        $sql_posts_total = $wpdb->get_var( "SELECT FOUND_ROWS();" );
        $max_num_pages = ceil($sql_posts_total / $post_per_page);
    
        return $sql_result;
    }

    thanks.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar