I'm trying to populate an Advanced Custom Fields' radio field pulling out the data from a custom post type located in the main blog of a multisite install.
For a better understanding I made this simple flow graphic.
So I created a function in order to pull out the data from Main Blog and show as radio items on child site.
The function looks like this and I used this as reference
function getctas($field) {
$field['choices'] = array();
switch_to_blog(1);
$args = array(
'post_type' => 'location_icons',
'posts_per_page' => '-1',
);
$ctas = new WP_Query( $args );
while ( $ctas->have_posts()) {
$ctas->the_post();
$choices = get_field('icon',false);
$choices = explode("\n", $choices);
foreach( $choices as $choice ):
$field['choices'][ $choice ] = '<img src="'.$choice.'"/>';
endforeach;
}
restore_current_blog();
return $field;
}
add_filter('acf/load_field/name=call_to_action_icon', 'getctas');
I get the options listed correctly (options are images), I successfully pulled out the field icon
from main blog and put as radio label and value.
The issue I'm having is that once the post is saved when I query it on the child's page template I get the correct images but the title of the post on blog 1 repeated. The ideal would be to have:
- Image
- Child Blog Post's Title
- Child Blog Post's Desc
And what I'm, instead getting is:
- Correct Image
- CTP Title that contains the image on blog 1
No description
Correct Image
- Same title as previous one
- No description
And so on.
If any of you need more clarifications to help me solve this I'd be pleased to explain further.