函数原型
get_terms_to_edit( int $post_id, string $taxonomy = ‘post_tag’ ): string|false|WP_Error
函数描述
Gets comma-separated list of terms available to edit for the given post ID.
是否弃用
未弃用
函数参数
-
$post_id
int
Required -
$taxonomy
string
Optional - The taxonomy for which to retrieve terms. Default
'post_tag'.Default:
'post_tag'
函数返回值
string|false|WP_Error
函数位置
File: wp-admin/includes/taxonomy.php.
函数源码
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;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |

