how could I get the pagination as I want to when query posts using get_posts function

Use paginate_links. It is meant to do pretty much just that. Plus, the ordinary pagination functions like next_posts_link (which I think you want instead of next_post_link) do not work reliably with custom queries, but next_post_link and previous_post_link are equally or more troublesome with custom queries.

With paginate_links you need to pass quite a bit of data, so read the Codex carefully.

Leave a Comment