Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get recent wordpress posts in Laravel

Tags:

I have a Wordpress site and a Laravel site and I want to display recent wordpress posts in the footer of Laravel site. How can I do this without having my wordpress database information in my config/database.php file and using it in the models? Can I get them using RSS?

like image 302
Ehsan Mousavi Avatar asked Oct 13 '18 06:10

Ehsan Mousavi


1 Answers

Recent WordPress was released with a huge thing called REST API – earlier it was possible only with external plugins. So now we can query WordPress database from external projects. Including Laravel.

set up a local WordPress website, and after installation you got that usual dashboard.

we can already make API calls after installation. No need to configure anything, we just launch the URL in the browser:

we’ve received a JSON with a list of posts – by default, WordPress creates one dummy post. Basically, URL structure for the API calls is simple:

/wp-json/wp/v2/[endpoint]?[parameters]

Yes, you’ve read it right, we can get posts, categories, tags and other things that are publicly available, so we don’t need any authentication here.

And we also can filter the data with GET parameters, like this:

/wp-json/wp/v2/posts?per_page=2&orderby=title

For more details open link:- Using WordPress REST API in Laravel

like image 91
Udhav Sarvaiya Avatar answered Nov 15 '22 05:11

Udhav Sarvaiya