返回介绍

get_terms_to_edit()

发布于 2017-09-11 00:21:05 字数 2824 浏览 951 评论 0 收藏 0

get_terms_to_edit( int $post_id,  string $taxonomy = 'post_tag' )

Get comma-separated list of terms available to edit for the given post ID.


description


参数

$post_id

(int) (Required)

$taxonomy

(string) (Optional) The taxonomy for which to retrieve terms.

Default value: 'post_tag'


返回值

(string|bool|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( join( ',', $term_names ) );

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

	return $terms_to_edit;
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-admin/includes/taxonomy.php: terms_to_edit
  • wp-includes/cache.php: wp_cache_add()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/functions.php: wp_list_pluck()
  • wp-includes/taxonomy.php: get_object_term_cache()
  • wp-includes/taxonomy.php: wp_get_object_terms()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/load.php: is_wp_error()
  • Show 3 more uses Hide more uses

Used By

  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::tags_html()
  • wp-admin/includes/taxonomy.php: get_tags_to_edit()
  • wp-admin/includes/template.php: get_inline_data()
  • wp-admin/includes/meta-boxes.php: post_tags_meta_box()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文