What is best practice for Controller and ACF for one cpt used in different locations?

I have a custom post type events with various ACF fields. I’m going to display different fields depending on which view it’s on - for example in the calendar view I’ll show date, time, location, and cost. In the Event Reports page I’ll show date, report, and loop through gallery images. On the Gallery page I’ll just show all the images.

In Controller is it better to specify the fields I need in a controller for each view like this:

class Calendar extends Controller
{
    // Pass on multiple fields from Advanced Custom Fields to the view
    protected $acf = ['date', 'time' etc...];
}

Or pass them all to everywhere like this:

class App extends Controller
{
    // Pass on all fields from Advanced Custom Fields
    protected $acf = true;
}

Hey, Neil! You’ve probably got this sorted out by now, but I think it comes down to personal preference more than anything. I’d personally be inclined to start off with the latter (turning them all on in App.php) for simplicity, and then go more restricted if for some reason it became necessary.

That said, if you do that, see this: https://github.com/soberwp/controller/issues/114

Thanks Matt. That’s good reassurance :slight_smile:

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.