Using one function with ACF from one Controller in another

Or maybe even something like this (havent tested this, just a quick example):

trait PressFunnel 
{
    public function PressFunnel($id = false) {
        $pressRepeater = get_field( 'press_stories', $id );  // false equals to current post

        //Maybe do something with a limit here
        return array_map(function ($item) { 
            return [
                'title'       => $item['title'],          
                'description' => $item['description'],
                'link'        => $item['link'],
                'date'        => $item['date'],
            ];
        }, $pressRepeater ?? [] );
    }
}
class TemplatePress extends Controller
{
    use PressFunnel ;
}
class TemplateWho extends Controller
{
    use PressFunnel {
        PressFunnel as ParentPressFunnel
    );

    public function PressFunnel($id = false) {
        $press = get_page_by_title( 'Press' );
        return $this->ParentPressFunnel($press->ID);
    }
}

Using $post_id false in the AFC get_field equals to current post.

Info about Overriding & Extending a PHP Trait Method:

1 Like