get_terms_to_edit

函式
get_terms_to_edit ( $post_id, $taxonomy = 'post_tag' )
引數
  • (int) $post_id
    Required:
  • (string) $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
    Required:
    Default: 'post_tag'
返回值
  • (string|false|WP_Error)
定義位置
相關方法
get_term_to_editget_tags_to_editget_user_to_editget_category_to_editget_post_to_edit
引入
2.8.0
棄用
-

get_terms_to_edit: 這個函式為編輯目的檢索一個術語(類別、標籤等)物件的陣列。它需要兩個引數:要檢索術語的分類法,以及一個用於過濾結果的可選引數陣列。它返回一個術語物件的陣列。

獲取逗號分隔的可用於編輯給定文章ID的術語列表。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
$post_id = (int) $post_id;
if ( ! $post_id ) {
return false;
}
$terms = get_object_term_cache( $post_id, $taxonomy );
if ( false === $terms ) {
$terms = wp_get_object_terms( $post_id, $taxonomy );
wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' );
}
if ( ! $terms ) {
return false;
}
if ( is_wp_error( $terms ) ) {
return $terms;
}
$term_names = array();
foreach ( $terms as $term ) {
$term_names[] = $term->name;
}
$terms_to_edit = esc_attr( implode( ',', $term_names ) );
/**
* Filters the comma-separated list of terms available to edit.
*
* @since 2.8.0
*
* @see get_terms_to_edit()
*
* @param string $terms_to_edit A comma-separated list of term names.
* @param string $taxonomy The taxonomy name for which to retrieve terms.
*/
$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
return $terms_to_edit;
}
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) { $post_id = (int) $post_id; if ( ! $post_id ) { return false; } $terms = get_object_term_cache( $post_id, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post_id, $taxonomy ); wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' ); } if ( ! $terms ) { return false; } if ( is_wp_error( $terms ) ) { return $terms; } $term_names = array(); foreach ( $terms as $term ) { $term_names[] = $term->name; } $terms_to_edit = esc_attr( implode( ',', $term_names ) ); /** * Filters the comma-separated list of terms available to edit. * * @since 2.8.0 * * @see get_terms_to_edit() * * @param string $terms_to_edit A comma-separated list of term names. * @param string $taxonomy The taxonomy name for which to retrieve terms. */ $terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy ); return $terms_to_edit; }
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
	$post_id = (int) $post_id;
	if ( ! $post_id ) {
		return false;
	}

	$terms = get_object_term_cache( $post_id, $taxonomy );
	if ( false === $terms ) {
		$terms = wp_get_object_terms( $post_id, $taxonomy );
		wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' );
	}

	if ( ! $terms ) {
		return false;
	}
	if ( is_wp_error( $terms ) ) {
		return $terms;
	}
	$term_names = array();
	foreach ( $terms as $term ) {
		$term_names[] = $term->name;
	}

	$terms_to_edit = esc_attr( implode( ',', $term_names ) );

	/**
	 * Filters the comma-separated list of terms available to edit.
	 *
	 * @since 2.8.0
	 *
	 * @see get_terms_to_edit()
	 *
	 * @param string $terms_to_edit A comma-separated list of term names.
	 * @param string $taxonomy      The taxonomy name for which to retrieve terms.
	 */
	$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );

	return $terms_to_edit;
}

常見問題

FAQs
檢視更多 >