Use this for pagination
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$mostpopular_args=array(
'post_type' => 'post',
'orderby' => 'meta_value_num',
'meta_key' => 'view_count',
'paged' => $paged,
'posts_per_page' => '10',
);
$wp_query = new WP_Query($mostpopular_args);
while ($wp_query->have_posts()): $wp_query->the_post();
get_the_title();
endwhile;
global $wp_query;
$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
) );
?>
Related Posts:
- Custom WP_Query order by post_meta and (author) user_meta
- How to paginate attachments in a secondary query as gallery?
- Add and in the header while looping over custom query in page template
- Paginated pages are showing correct content but pagination links are not
- Search – Ajax – Alter Query Parameters with Pagination
- Transient pagination not working properly
- WP_QUERY loop, offset in the arguments and the paginate_links – can these work together?
- How to output different posts per page?
- Create ONE callback for all page templates, post filter queries + paginated pages, triggering pagination via AJAX
- Pagination of a WP_Query Loop in a child-page page template
- paging in WP_Query on static page
- Get pagination working for custom loops within page templates
- WordPress Pagination changes my template
- Pretty urls for custom pagination
- Multisite pagination issue by multi query archive 404
- Pagination on template page for custom query redirecting to index.php
- Yoast primary category query modification
- Notice thrown when creating numeric pagination on custom query
- WP_Query custom order and pagination
- Unable to paginate a custom page query
- I am officially missing something about transient posts
- Pagination of custom page with custom fields query
- Why pagination is not working with tax_query param?
- paginate_links method doesn’t show second page of my custom wp_query
- Pagination Shows Up But Won’t Work on Custom Gallery Page
- Paginate nested query of child posts
- Custom pagination (Title, date and teaser)
- Using URL variables on a custom WP_Query
- Pagination in custom query in a category page
- Horizontally paginate through sets of blog posts?
- Pagination in WP query with transient API
- error with $query->have_posts()
- Search results stuck on page 1
- Pagination only showed when no category is set in wp_query
- Find out total number of pages in global query on archive page?
- WordPress Pagination Not Working – Always Showing First Pages Content
- get_query_var function not working at all
- get_query_var( ‘paged’ ) not working outside of homepage
- Pagination returns 404 after page 20
- Make a WP Query search match exactly the search term
- Query WooCommerce orders where meta data does not exist
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Show only oldest post by author
- How to get the posts published in last two days using WP_Query?
- Dynamically Override Fancy Title – Part II
- Can not switch the queried post in pre_get_posts hook
- Woocommerce custom loop to show all the products [closed]
- Get the post permalink within the loop but without additional DB query
- Pagination 404 errors for author posts query on author.php
- Pagination problem after WP_Query with tag filtering
- Pagination stops at page 6
- Paginated HTML Sitemap
- Pagination is broken and I need help fixing it
- Query total number of posts
- Creating a custom search for a specific post type
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- Custom query for sidebar isn’t returning results
- How is WP_Query parsed to determine which template to request?
- pagination with numbers for WP_User_Query
- Query posts intersecting tags and categories
- Pagination on static Posts page
- Query Page Content From Theme Options?
- Modify Search Query if original Query gave no results
- How to cache wp_query with pagination using transients?
- Include current post into loop
- Filter post query to only show direct children of category
- Paging + WP Query
- WP_User_Query orderby meta_val_num
- max_num_pages says 4, yet I am only able to navigate to the third page
- Paginate pages with dynamic query
- Trouble Making WP_Query paged
- What’s the best way to make a blog page on WordPress?
- paginate_links appearing on page but it doesn’t actually paginate – pagination on a static page with a dynamic `post_type` argument on a static page
- Query pages created by deleted users
- Exclude post from wp_query based on custom field boolean
- Get posts that match defined arrays of tags
- Order posts by tags count?
- Strange results from WP_Query
- Is there a way to control both Order By and Order query parameters from one input field
- I need query_posts() to order results first by a meta value and then by post ID
- return child post if available otherwise parent post
- Search has query that will return no results
- WP Query – Search in title or author_name
- URL to Post Archive of Custom Query
- orderby in WP_QUERY – Use the order from the Dashboard
- Random posts in WP_Query when searching by tag
- Pagination returns 404 after page 20
- Ordering Posts by parent category, name ascending
- WP_Query always returning the last custom post
- How to query post into a complex slider
- Loop through multiple custom fields with increasing number
- How to organize a WP_Query’s list of posts by category and display category title?
- Need help setting up a search form for wordpress [duplicate]
- Ordering Custom WP_Query loop by meta key value with pagination
- Get WP_Query query after execution?
- Pagination in custom query not working [duplicate]
- paginate_links() on page (shortcode output)
- Pagination showing same posts despite changing page
- Pagination on custom post type not working
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise