AdvancedCustomFields / AdvancedCustomFields/acf
Option page doesn't return other site's field when using switch_to_blog
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
I'm making an alert setup for my site that scours the sub sites to know if they have also alerts to show on the whole network.
So here is what I do (abbreviated):
if ( function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) :
$sites = get_sites();
foreach ( $sites as $site ) :
switch_to_blog($site->blog_id);
while (have_rows('repeater_alert', 'option')) : the_row();
$title = get_sub_field('alert_title');
$from = get_bloginfo('name');
endwhile;
endforeach;
endif;
restore_current_blog();
And well, on site #1 (Primary site of network) looking into site #2, everything works, but when on site #2, title will contain the alerts of site #2, but the from will be correct, giving out the name of site #1.
So for some reason, when switching to the primary site of the multisite network, WP gets it to load that site, but not ACF.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported reproduction using switch_to_blog(), have_rows(), get_sub_field(), get_bloginfo(), and restore_current_blog() across two WordPress multisite sites. Compare the site context used by ACF option fields with the context used by get_bloginfo(); done means fields and the site name consistently come from the switched site.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100