Query specific number of posts for each post type in specific order

You can use WP_Query() with paged array key to pass the current page number: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘post_type’ => ‘articles’, ‘posts_per_page’ => 4, ‘paged’ => $paged ); $articles = new WP_Query($args); //////////////////////////////// $args = array( ‘post_type’ => ‘news’, ‘posts_per_page’ => 1, ‘meta_query’ => array( array( ‘key’ => … Read more

Pagination not working with custom loop

I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop. An exmaple: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args=array( ‘post_type’=>’post’, ‘cat’ => 6, ‘posts_per_page’ => 5, ‘paged’=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* … Read more

The next_posts_link() works only with original $wp_query

next_posts_link and previous_posts_link use the global $wp_query. function get_next_posts_link( $label = null, $max_page = 0 ) { global $paged, $wp_query; http://core.trac.wordpress.org/browser/tags/3.5/wp-includes/link-template.php#L1523 That means you need to do something like this to get those to work correctly. $orig_query = $wp_query; $wp_query = new WP_Query($args); // the rest of your code $wp_query = $orig_query; If you are … Read more

How does offset works on pagination? (get_results)

The problem here is the LIMIT, it’ll just count the first page and not the entire query. I had solved it by providing a secondary SQL query for counting the max pages. thanks for my friends for this tip. here’s the complete code. function.php function spiciest(){ global $wpdb, $paged, $max_num_pages; $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)