Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Generator::get_term_id( string $term_name, string $tax )

Get a WP Term ID for a term by taxonomy and term name attempts to find a given term by name first to prevent duplicates during imports


Description Description


Parameters Parameters

$term_name

(string) (Required) term name

$tax

(string) (Required) taxonomy slug


Top ↑

Return Return

(int|void) term id or void when error


Top ↑

Source Source

File: includes/class.llms.generator.php

	private 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 ) ) {
				return $this->error->add( 'term-creation', sprintf( __( 'Error creating new term "%s"', 'lifterlms' ), $term_name ) );
			} else {
				$this->increment( 'terms' );
			}
		}

		return $term['term_id'];

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.