Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Bidirectional fields #121

Open
mortensassi opened this issue Jul 14, 2020 · 1 comment
Open

Feature Request: Bidirectional fields #121

mortensassi opened this issue Jul 14, 2020 · 1 comment

Comments

@mortensassi
Copy link

When i used ACF tohether ACF-Extended i really enjoyed having the "Bidirectional Field" Option on relatinship fields - Is it possible to implement such functionality to this plugin? Would love to hear your thoughts. (And sorry for being so ignorant and not submitting my own solution)

@robrecord
Copy link

robrecord commented May 19, 2022

You can do this when you set up addRelationship.

class AttachmentProject extends Partial
{
    public function fields()
    {
        $attachmentProject = new FieldsBuilder('attachment_project');

        $attachmentProject
            ->addRelationship('project', [
                'post_type' => 'project',
                'acfe_bidirectional' => [
                    'acfe_bidirectional_enabled' => true,
                    'acfe_bidirectional_related' => [
                        'field_project_attachment',
                    ],
                ],
            ]);

        return $attachmentProject;
    }
}
class ProjectAttachment extends Partial
{
    public function fields()
    {
        $projectAttachment = new FieldsBuilder('project_attachment');

        $projectAttachment
            ->addRelationship('attachment', [
                'post_type' => 'attachment',
                'acfe_bidirectional' => array(
                    'acfe_bidirectional_enabled' => true,
                    'acfe_bidirectional_related' => [
                        'field_attachment_project',
                    ],
                ),
            ]);

        return $projectAttachment;
    }
}

When referencing the other field to link, the name is field_ plus whatever you've named the other field's FieldsBuilder instance (not sure why it takes that name rather than the relationship field name). Or you can get the field name from looking at the admin area in the web inspector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants