Blog

WordPress load more posts using ajax

WordPress load more posts using ajax

Hi guys this is new post for WordPress series, From this post i am going elaborate a interesting topic that How to show WordPress posts or custom post type’s post with load more button.

This is very fancy and advanced way to show your WordPress posts without pagination and page refresh.

And also this is very handy to use in particular section of div like you can use in one page website or wherever you want.

So we can achieve this task using HTML in template page and j Query and functions.php page.
Please see the Working Example .

So now we first write html code where we fetch WordPress posts using ajax.

Now very firstly i created a  div structure of html.I created result container that will contain all appended dynamic posts and there is one more div that contain button of load more.
Okay copy this code and put this code where you want to show.

Our div container is ready to use so now we have to create some java script functions that will handle ajax request on button click.
You can copy this code into your js file and include into page where you want use in word press.

Java script functions are ready to call server request to fetch posts records from MySQL table but her i am using word press MySQL table so i use WP_Query method that will return posts.
So please note there is a “post_type” in args array variable.So i use “demo” that is custom post type you can choose your custom post type like (page,post,property,listing.. etc).
Now its time to copy php code into your functions.php