Home › Forums › General Issues › Relationship field for multisite › Reply To: Relationship field for multisite
Hi,
It’s a really old post but a solution with ACF 4 and a page link field is to create a new field type in a plugin or in functions.php of the theme. I suppose it can be done with a post field too. Here’s an example :
class acf_field_page_link_multisite extends acf_field_page_link
{
function __construct()
{
// vars
$this->name = 'post_object_multisite';
$this->label = __("Page Link Multisite",'acf');
$this->category = __("Relational",'acf');
$this->defaults = array(
'post_type' => array('all'),
'multiple' => 0,
'allow_null' => 0,
);
// do not delete!
acf_field::__construct();
}
function create_field( $field )
{
// Switch to the blog you want
switch_to_blog(5);
parent::create_field($field);
restore_current_blog();
}
function create_options( $field )
{
switch_to_blog(5);
parent::create_options($field);
restore_current_blog();
}
function format_value_for_api( $value, $post_id, $field )
{
switch_to_blog(5);
$value = parent::format_value_for_api($value, $post_id, $field);
restore_current_blog();
return $value;
}
}
new acf_field_page_link_multisite();
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.