Complex query and posts pagination

First of all, the post_nav_link() function is used to paginate the main query on home and archive pages. It does not work with custom queries (unless you hack the main query which I strongly discourage, it is the same as using query_posts then). To paginate your custom query, you need to use next_posts_link() previous_posts_link() which … Read more

How to display all posts from standard posts to custom post types in a loop with pagination?

You don’t need a custom query to include CPTs in homepage posts in normal cases. Just use pre_get_posts. function wpse215208_include_all_cpt( $query ) { if ( is_home() && $query->is_main_query() ) { $query->set(‘post_type’, array( ‘post’, ‘photo’, ‘video’, ‘web’ ) ); } } add_action(‘pre_get_posts’, ‘wpse215208_include_all_cpt’);

Pagination Issue – /page/2 404

Pieter was correct. It was messing up due to the custom loop I was running on the archive page. I removed the custom loop, and then adjusted the arguments with pre_get_posts. The strange thing was that, to test if it was this issue, running a custom loop on an archive page was the issue, I … Read more

Customize WordPress Core Template

Since it isn’t pluggable, you could define a replacement function in your theme. In your theme’s functions.php file, copy the core paginate_links() function, rename the function – perhaps my_paginate_links(), modify the source code so it creates the anchor tag you need, and then call your new function wherever you need it in the rest of … Read more

WP-PageNavi is showing the first page only

In case of wp_query, you can’t use shortcode this way <?php wp_pagenavi(); ?> You need to use variable (in which you are storing wp_query) in array inside shortcode. Use shortcode like this instead. Replace above shortcode with below one. <?php wp_pagenavi( array( ‘query’ => $query_slider ) ); ?> UPDATE This is a way in which … Read more

Five posts from a category in footer

First: don’t use query_posts. Second: use $wp_query instead: $args = array ( ‘category_name’ => ‘entertainment’, ‘posts_per_page’=> 5 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } echo ‘</ul>’; /* Restore original Post Data */ wp_reset_postdata(); } else … Read more

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