wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema



wp_set_post_terms › WordPress Function

Desde2.8.0
Obsoleton/a
wp_set_post_terms ( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false )
Parâmetros: (4)
  • (int) $post_id Optional. The Post ID. Does not default to the ID of the global $post.
    Required: No
    Padrão:
  • (string|array) $terms Optional. An array of terms to set for the post, or a string of terms separated by commas. Hierarchical taxonomies must always pass IDs rather than names so that children with the same names but different parents aren't confused. Default empty.
    Required: No
    Padrão: (empty)
  • (string) $taxonomy Optional. Taxonomy name. Default 'post_tag'.
    Required: No
    Padrão: 'post_tag'
  • (bool) $append Optional. If true, don't delete existing terms, just add on. If false, replace the terms with the new terms. Default false.
    Required: No
    Padrão: false
Ver:
Retorna:
  • (array|false|WP_Error) Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
Definido em:
Codex:

Sets the terms for a post.



Fonte

function wp_set_post_terms( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false ) {
	$post_id = (int) $post_id;

	if ( ! $post_id ) {
		return false;
	}

	if ( empty( $terms ) ) {
		$terms = array();
	}

	if ( ! is_array( $terms ) ) {
		$comma = _x( ',', 'tag delimiter' );
		if ( ',' !== $comma ) {
			$terms = str_replace( $comma, ',', $terms );
		}
		$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
	}

	/*
	 * Hierarchical taxonomies must always pass IDs rather than names so that
	 * children with the same names but different parents aren't confused.
	 */
	if ( is_taxonomy_hierarchical( $taxonomy ) ) {
		$terms = array_unique( array_map( 'intval', $terms ) );
	}

	return wp_set_object_terms( $post_id, $terms, $taxonomy, $append );
}