max_num_pages > 1 ) { $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big , '%#%' , esc_url( get_pagenum_link( $big ) ) ) , 'format' => '?paged=%#%' , 'current' => max( 1 , get_query_var( 'paged' ) ) , 'total' => $wp_query->max_num_pages , 'prev_text' => __( '<' , 'green' ) , 'next_text' => __( '>' , 'green' ) ) ); } } /** * Retorna uma lista de termos ordenados pela data de utilização. * * @param string $taxonomy * @param integer $limit * @param integer $paged * @return \WP_Term[] */ function get_terms_order_by_posts_publish_date(string $taxonomy, int $limit = 10, int $paged = 1){ global $wpdb; if(false) $wpdb = new \wpdb(1,2,3,4); $offset = $limit * ($paged - 1); $sql = " SELECT t.term_id, t.name, t.slug, tx.term_taxonomy_id, tx.taxonomy, tx.description, tx.parent, tx.count FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tx ON tx.term_id = t.term_id LEFT JOIN $wpdb->term_relationships tr ON tr.term_taxonomy_id = tx.term_taxonomy_id LEFT JOIN $wpdb->posts p ON p.ID = tr.object_id WHERE tx.taxonomy = '$taxonomy' AND p.post_type = 'coluna' AND tr.object_id IN ( SELECT MAX(object_id) FROM $wpdb->term_relationships WHERE term_taxonomy_id = tr.term_taxonomy_id ) GROUP BY tx.term_taxonomy_id ORDER BY p.post_date DESC LIMIT $limit OFFSET $offset "; $results = $wpdb->get_results($sql); $terms = array_map(function($term){ return new \WP_Term($term); }, $results); return $terms; } function get_posts_ranking() { if(!class_exists('\\AjaxPageviews')){ return; } $cache_key = 'most_viewed_within_hour'; // use wp cache for optimization $ids = wp_cache_get( $cache_key ); if ( $ids === false ) { $most_viewed = \AjaxPageviews::get_top_viewed(500, ['post_type' => 'post', 'from' => date('Y-m-d H:00', strtotime('-24 hour'))]); $ids = array(); foreach ( $most_viewed as $post => $value ) { array_push( $ids, $value->post_id ); } // stores in cache for 1 hour wp_cache_add( $cache_key, $ids, HOUR_IN_SECONDS ); } //var_dump($ids); return $ids; } function get_post_ranking_position( $post_id ) { $posts_ranking = get_posts_ranking(); // the function already returns a cached value // linear search foreach ( $posts_ranking as $key => $id ) { if ($post_id == $id) { //print('The post(' . $id . ') rank position is ' . ($key + 1)); return $key + 1; } } return false; }