LLMS_Abstract_Generator_Posts::get_term_id( string $term_name, string $tax )
Get a WP Term ID for a term by taxonomy and term name
Description Description
Attempts to find a given term by name first to prevent duplicates during imports.
Parameters Parameters
- $term_name
-
(string) (Required) Term name.
- $tax
-
(string) (Required) Taxonomy slug.
Return Return
(int) The created WP_Term term_id
.
Source Source
File: includes/abstracts/llms-abstract-generator-posts.php
protected function get_term_id( $term_name, $tax ) { $term = get_term_by( 'name', $term_name, $tax, ARRAY_A ); // Not found, create it. if ( ! $term ) { $term = wp_insert_term( $term_name, $tax ); if ( is_wp_error( $term ) ) { throw new Exception( sprintf( __( 'Error creating new term "%s".', 'lifterlms' ), $term_name ), self::ERROR_CREATE_TERM ); } /** * Triggered when a new term is generated during an import * * @since 4.7.0 * * @param array $term Term information array from `wp_insert_term()`. * @param string $tax Taxonomy name. */ do_action( 'llms_generator_new_term', $term, $tax ); } return $term['term_id']; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.7.0 | Moved from LLMS_Generator and updated method access from private to protected . Throws an exception in favor of returning null when an error is encountered. |
3.3.0 | Introduced. |