get_term_field

Definition:
function get_term_field( $field, $term, $taxonomy, $context = 'display' ) {}

Get sanitized Term field.
Does checks for $term, based on the $taxonomy. The function is for contextual reasons and for simplicity of usage. See sanitize_term_field() for more information.

Parameters

  • string $field: Term field to fetch
  • int $term: Term ID
  • string $taxonomy: Taxonomy Name
  • string $context: Optional, default is display. Look at sanitize_term_field() for available options.

Return values

returns:Will return an empty string if $term is not an object or if $field is not set in $term.

Source code

function get_term_field( $field, $term, $taxonomy, $context = 'display' ) {

	$term = (int) $term;

	$term = get_term( $term, $taxonomy );

	if ( is_wp_error($term) )

		return $term;



	if ( !is_object($term) )

		return '';



	if ( !isset($term->$field) )

		return '';



	return sanitize_term_field($field, $term->$field, $term->term_id, $taxonomy, $context);

}

1759

get_term_feed_link

Definition:
function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {}

Retrieve the feed link for a term.
Returns a link to the feed for all posts in a given term. A specific feed can be requested or left blank to get the default feed.

Parameters

  • int $term_id: ID of a category.
  • string $taxonomy: Optional. Taxonomy of $term_id
  • string $feed: Optional. Feed type.

Return values

returns:Link to the feed for the term specified by $term_id and $taxonomy.

Defined filters

  • category_feed_link
    apply_filters( 'category_feed_link', $link, $feed )
  • category_feed_link
    apply_filters( 'category_feed_link', $link, $feed )
  • taxonomy_feed_link
    apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy )

Source code

function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) {

	global $wp_rewrite;



	$term_id = ( int ) $term_id;



	$term = get_term( $term_id, $taxonomy  );



	if ( empty( $term ) || is_wp_error( $term ) )

		return false;



	if ( empty( $feed ) )

		$feed = get_default_feed();



	$permalink_structure = get_option( 'permalink_structure' );



	if ( '' == $permalink_structure ) {

		if ( 'category' == $taxonomy ) {

			$link = home_url("?feed=$feed&cat=$term_id");

		}

		elseif ( 'post_tag' == $taxonomy ) {

			$link = home_url("?feed=$feed&tag=$term->slug");

		} else {

			$t = get_taxonomy( $taxonomy );

			$link = home_url("?feed=$feed&$t->query_var=$term->slug");

		}

	} else {

		$link = get_term_link( $term_id, $term->taxonomy );

		if ( $feed == get_default_feed() )

			$feed_link = 'feed';

		else

			$feed_link = "feed/$feed";



		$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' );

	}



	if ( 'category' == $taxonomy )

		$link = apply_filters( 'category_feed_link', $link, $feed );

	elseif ( 'post_tag' == $taxonomy )

		$link = apply_filters( 'category_feed_link', $link, $feed );

	else

		$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy );





	return $link;

}

1757

get_term_children

Definition:
function get_term_children( $term_id, $taxonomy ) {}

Merge all term children into a single array of their IDs.
This recursive function will merge all of the children of $term into the same array of term IDs. Only useful for taxonomies which are hierarchical.

Parameters

  • string $term_id: ID of Term to get children
  • string $taxonomy: Taxonomy Name

Return values

returns:List of Term Objects. WP_Error returned if $taxonomy does not exist

Source code

function get_term_children( $term_id, $taxonomy ) {

	if ( ! taxonomy_exists($taxonomy) )

		return new WP_Error('invalid_taxonomy', __('Invalid Taxonomy'));



	$term_id = intval( $term_id );



	$terms = _get_term_hierarchy($taxonomy);



	if ( ! isset($terms[$term_id]) )

		return array();



	$children = $terms[$term_id];



	foreach ( (array) $terms[$term_id] as $child ) {

		if ( isset($terms[$child]) )

			$children = array_merge($children, get_term_children($child, $taxonomy));

	}



	return $children;

}

1755

get_term_by

Definition:
function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {}

Get all Term data from database by Term field and data.
Warning: $value is not escaped for ‘name’ $field. You must do it yourself, if required.

Parameters

  • string $field: Either ‘slug’, ‘name’, or ‘id’
  • string|int $value: Search for this term value
  • string $taxonomy: Taxonomy Name
  • string $output: Constant OBJECT, ARRAY_A, or ARRAY_N
  • string $filter: Optional, default is raw or no WordPress defined filter will applied.

Return values

returns:Term Row from database. Will return false if $taxonomy does not exist or $term was not found.

Defined filters

  • get_term
    apply_filters('get_term', $term, $taxonomy)
  • get_$taxonomy
    apply_filters("get_$taxonomy", $term, $taxonomy)

Source code

function get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw') {

	global $wpdb;



	if ( ! taxonomy_exists($taxonomy) )

		return false;



	if ( 'slug' == $field ) {

		$field = 't.slug';

		$value = sanitize_title($value);

		if ( empty($value) )

			return false;

	} else if ( 'name' == $field ) {

		// Assume already escaped

		$value = stripslashes($value);

		$field = 't.name';

	} else {

		$term = get_term( (int) $value, $taxonomy, $output, $filter);

		if ( is_wp_error( $term ) )

			$term = false;

		return $term;

	}



	$term = $wpdb->get_row( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s AND $field = %s LIMIT 1", $taxonomy, $value) );

	if ( !$term )

		return false;



	wp_cache_add($term->term_id, $term, $taxonomy);



	$term = apply_filters('get_term', $term, $taxonomy);

	$term = apply_filters("get_$taxonomy", $term, $taxonomy);

	$term = sanitize_term($term, $taxonomy, $filter);



	if ( $output == OBJECT ) {

		return $term;

	} elseif ( $output == ARRAY_A ) {

		return get_object_vars($term);

	} elseif ( $output == ARRAY_N ) {

		return array_values(get_object_vars($term));

	} else {

		return $term;

	}

}

1753

get_terms_to_edit

Definition:
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {}

Parameters

  • unknown_type $post_id
  • $taxonomy

Defined filters

  • terms_to_edit
    apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy )

Source code

function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {

	$post_id = (int) $post_id;

	if ( !$post_id )

		return false;



	$tags = wp_get_post_terms($post_id, $taxonomy, array());



	if ( !$tags )

		return false;



	if ( is_wp_error($tags) )

		return $tags;



	foreach ( $tags as $tag )

		$tag_names[] = $tag->name;

	$tags_to_edit = join( ',', $tag_names );

	$tags_to_edit = esc_attr( $tags_to_edit );

	$tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy );



	return $tags_to_edit;

}

1751