Accessing WordPress Post through Laravel

Accessing WordPress Post through Laravel

query-into-wordpress-db-from-laravel

In the previous tutorial we have learn as how to Install WordPress inside a Laravel application in a subdirectory and same domain and access it using example.com/blog/. In this tutorial we will be learning as how to access WordPress post, page, or any custom post type data through Laravel.
There are 2 ways to do this

  1. Through WordPress REST API
  2. Directly access WordPress database through Laravel Modal

Directly access WordPress database through Laravel Modal

We need to create Modal BlogPost and BlogPostmeta to access data from wp_posts and wp_postmeta table respectively.

Modal BlogPost.php

Modal BlogPostmeta.php

Now as we have set the database connection and model last thing that we need is to retrieve post. In controller we have to use our Post model to get post as use App\BlogPost;.

$posts will hold all your active published post and under postmetas key it will be holding all the meta’s that are related to that specific post.

In next tutorial we will be digging deep into WP Comments and WP Author.

Share this Post:

About Raunak Gupta

I'm an expert Laravel, WooCommerce, WordPress theme and plugin developer, over the time I have developed several sites and applications. I like to help the upcoming developer, So I share my experience through this blog.  

Related Posts:

Leave a Comment

Your email address will not be published. Required fields are marked *


*