I’m trying to retrieve all post type of every multisite to populate a select from ACF PRO. But when I var_dump receive nothing but. It seems I dont even pass on the while have post. But I know "wphr_hr_recruitment" have like 5 instances, and also this code works on page template.
function getSites(){
$args = array(
'network_id' => null,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$sites = wp_get_sites( $args );
wp_reset_postdata();
return $sites;
}
function acf_load_job( $field ) {
$jobs=array();
$currentJobs=array();
$sites = getSites();
foreach ( $sites as $site) {
switch_to_blog(intval($site['blog_id']));
$query = new WP_Query( [
'post_type' => 'wphr_hr_recruitment',
'post_status' => 'publish',
'posts_per_page' => -1,
'order' => 'DESC',
'orderby' => 'post_date'
]);
if ( $query->have_posts() ) :
while ( have_posts()){
// $query->next_post();
$currentJobs[] = $query->post;
}
endif;
wp_reset_postdata();
restore_current_blog();
}
foreach($currentJobs as $currentJob){
$jobs[$currentJob["ID"]] = $currentJob["post_title"];
}
$field['required'] = true;
$field['choices'] = $jobs;
return $field;
}``
The function GetSites retreive all ID so this part seems to work
2
Answers
I found something like this, and it's actually work;
Use Network_query