LLMS_Generator_Courses::add_course_terms( obj $course_id, array $raw_terms )
Add taxonomy terms to a course
Parameters Parameters
- $course_id
-
(obj) (Required) WP_Post ID of a Course.
- $raw_terms
-
(array) (Required) Array of raw term arrays.
Return Return
(void)
Source Source
File: includes/class-llms-generator-courses.php
protected function add_course_terms( $course_id, $raw_terms ) {
$taxes = array(
'course_cat' => 'categories',
'course_difficulty' => 'difficulty',
'course_tag' => 'tags',
'course_track' => 'tracks',
);
foreach ( $taxes as $tax => $key ) {
if ( ! empty( $raw_terms[ $key ] ) && is_array( $raw_terms[ $key ] ) ) {
// We can only have one difficulty at a time.
$append = ( 'difficulty' === $key ) ? false : true;
$terms = array();
// Find term id or create it.
foreach ( $raw_terms[ $key ] as $term_name ) {
if ( empty( $term_name ) ) {
continue;
}
$term_id = $this->get_term_id( $term_name, $tax );
if ( $term_id ) {
$terms[] = $term_id;
}
}
wp_set_post_terms( $course_id, $terms, $tax, $append );
}
}
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.7.0 | Moved from LLMS_Generator and made protected instead of private. |
| 3.7.5 | Unknown. |
| 3.3.0 | Introduced. |