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?
2 Answers
You can get the posts by calling an API endpoint:
yoursiteurl/wp-json/wp/v2/posts
It will return all the posts in a json format. You can also see the reference from here.

- 544
- 1
- 7
- 18

- 3,603
- 1
- 14
- 26
-
You can use file_get_content instead in side the function of model or controller whereever you want. – Tristup Oct 13 '18 at 06:20
-
$result_from_json = file_get_contents('yoursiteurl/wp-json/wp/v2/posts'); $dataArr=json_decode($result_from_json,true ); print_r($dataArr); //print in array – Tristup Oct 13 '18 at 06:21
-
I'm getting " You don't have permission to access /wp-json/wp/v2/posts on this server. " error! – Ehsan Mousavi Oct 13 '18 at 06:26
-
First you try that url in browser and let me know what exactly showing – Tristup Oct 13 '18 at 06:29
-
It's showing "Forbidden You don't have permission to access /wp-json/wp/v2/posts on this server." – Ehsan Mousavi Oct 13 '18 at 06:30
-
add it define('JWT_AUTH_SECRET_KEY', 'your-top-secrect-key'); wp-config.php //anything you want but unique. – Tristup Oct 13 '18 at 06:31
-
Where and how to use defined secret key? – Ehsan Mousavi Oct 13 '18 at 06:59
-
Just paste the code into wp-config.php [ your-top-secrect-key = anything unique ] – Tristup Oct 13 '18 at 07:08
-
Did it and still have the issue – Ehsan Mousavi Oct 13 '18 at 07:10
-
I have the issue even when I'm logged in to my wordpress site! – Ehsan Mousavi Oct 13 '18 at 07:14
-
set the permalink to Post name and check it again – Tristup Oct 13 '18 at 08:12
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

- 9,380
- 13
- 53
- 64