Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dgoze/fcd9590cb4e05f6f5b9ba2a62da39e38 to your computer and use it in GitHub Desktop.
Save dgoze/fcd9590cb4e05f6f5b9ba2a62da39e38 to your computer and use it in GitHub Desktop.
Function to return an ACF field value for all the subsites on a network
<?php
function getAllCRMIds() {
global $wpdb;
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != {$wpdb->blogid} AND site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' order by blog_id", ARRAY_A);
// array_unshift($blogs, 1); /*Including parent blog in the array*/
$crm_to_blog = array();
foreach($blogs as $blog) {
switch_to_blog( $blog[ 'blog_id' ] );
$posts = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}posts WHERE post_type='imoveis' AND post_status='publish' ORDER BY RAND() DESC LIMIT 10");
$count = 0;
$CRMID=get_field('client_crm_id','option');
$crm_to_blog[] = array('crm_id'=> $CRMID, 'blog_id' =>$blog[ 'blog_id' ]);
}
print_r($crm_to_blog);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment