Feature #11298 » cac-fill-disciplinary-clusters.php
| 1 |
<?php
|
|---|---|
| 2 |
|
| 3 |
$taxonomy = 'cac_course_disciplinary_cluster'; |
| 4 |
|
| 5 |
$course_ids = get_posts( [ |
| 6 |
'post_type' => 'cac_course', |
| 7 |
'nopaging' => true, |
| 8 |
'fields' => 'ids', |
| 9 |
] ); |
| 10 |
|
| 11 |
foreach ( $course_ids as $course_id ) { |
| 12 |
$course = new \CAC\Courses\Course( $course_id ); |
| 13 |
|
| 14 |
$clusters = []; |
| 15 |
|
| 16 |
// Combine them all.
|
| 17 |
$site_ids = $course->get_site_ids(); |
| 18 |
foreach ( $site_ids as $site_id ) { |
| 19 |
$site_clusters = cac_get_site_disciplinary_clusters( $site_id ); |
| 20 |
if ( $site_clusters ) { |
| 21 |
$clusters = array_merge( $clusters, $site_clusters ); |
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
$group_ids = $course->get_group_ids(); |
| 26 |
foreach ( $group_ids as $group_id ) { |
| 27 |
$group_clusters = cac_get_group_disciplinary_clusters( $group_id ); |
| 28 |
if ( $group_clusters ) { |
| 29 |
$clusters = array_merge( $clusters, $group_clusters ); |
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
if ( ! $clusters ) { |
| 34 |
return; |
| 35 |
}
|
| 36 |
|
| 37 |
$clusters = array_unique( $clusters ); |
| 38 |
|
| 39 |
wp_set_object_terms( $course_id, $clusters, $taxonomy ); |
| 40 |
}
|