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

Add Bidirectional Relationships convenience method #161

Merged
merged 16 commits into from
Feb 22, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add Bidirectional trait
  • Loading branch information
kaelansmith committed Feb 21, 2025
commit 4c674b581672916182d917459928b62dd0055538
29 changes: 29 additions & 0 deletions src/Fields/Settings/Bidirectional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* Copyright (c) Vincent Klaiber
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @see https://github.com/vinkla/extended-acf
*/

declare(strict_types=1);

namespace Extended\ACF\Fields\Settings;

trait Bidirectional
{
/**
* Create a bidirectional relationship between two or more fields. Note: this requires setting a custom key for each related field via the `key` method, and passing those related fields' keys to this method.
* @see https://www.advancedcustomfields.com/resources/bidirectional-relationships/ for details & caveats
*/
public function bidirectional(array|string $keys): static
{
$this->settings['bidirectional'] = 1;
$this->settings['bidirectional_target'] = is_array($keys) ? $keys : [$keys];

return $this;
}
}