How to fix pagination for custom loops?

The Problem By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); When you use a custom query, you create … Read more

how to show posts on different pages if number of post per page is one

First of all, never use query_posts(), use WP_Query() instead. (Learn More) With your WP_Query() use paged parameter in the argument array, like: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘posts_per_page’ => 1, ‘paged’ => $paged ); $cat_query = new WP_Query( $args ); ?> And for the pagination link, go with: <?php … Read more

What is wrong with this pagination code?

The main query runs before the template is loaded, and WordPress decides what template to load based on the results of that query. You say your default posts_per_page is set to 200, and there are 180 posts in that category, so as far as WordPress knows, there is no page 2. Your custom query that … Read more

paging is not working properly on news archives page [duplicate]

Using your custom get_posts() you are ignoring the $paged var. In this way, you’ll see always posts from the first page. According the Codex Page if you would like to alter the main query before it is executed, you can hook into it using pre_get_posts. function my_post_queries( $query ) { if (!is_admin() && $query->is_main_query()){ $query->set(‘posts_per_page’, … Read more

How to fix pagination for custom loops?

The Problem By default, in any given context, WordPress uses the main query to determine pagination. The main query object is stored in the $wp_query global, which is also used to output the main query loop: if ( have_posts() ) : while ( have_posts() ) : the_post(); When you use a custom query, you create … Read more

Stop loading more posts if none left AJAX

Yes use wp_query 🙂 Anyway, to prevent loading posts while you’re out of pages, you need to know the current page number last loaded and the total number of pages that exist. Total pages that exist: $max = $wp_query->max_num_pages; Current page: just count it in your load loop, so set the var to 1, then … Read more

Pagination always adding “Next” link when results come from Custom Post Type WP_query

/doctors/ is a post type archive, so we can check if that query is being run in the pre_get_posts action via the conditional tag is_post_type_archive( ‘doctors’ ) and modify those queries accordingly. WordPress passes the query object to the function by reference ( $query in this example ), so we can modify the query vars … Read more

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