Sage9 controller for single custom post type

Hi guys,
I’m trying to create a controller for a single custom post type I’ve created.

In my case, I have this situation:

custom post type name => portfolio_project
single template => single-portfolio_project.blade.php
controller file and path => app/Controller/SinglePortfolioProject.php
controller class => SinglePortfolioProject

but I can’t use the data exported from controller.
Where I’m wrong?

I’m using this version of pkg "soberwp/controller": "~2.1.0" in my composer.json.

1 Like

UPDATE

I found the solution! In my case I wrote the wrong name for controller file and class name. Here’s the correct setup:

custom post type name => portfolio_project
single template => single-portfolio_project.blade.php
controller file and path => app/Controller/SinglePortfolio_project.php
controller class => SinglePortfolio_project

So if you have a name for a custom post type like this custom_post_type the correct naming for controller is Custom_post_type.

I hope this could be useful.

Ciao!

6 Likes