get_terms_to_edit
Get comma-separated list of terms available to edit for the given post ID.
Description
Returns (string|bool|WP_Error)
Parameters (2)
- 0. $post_id (int)
- The post id.
- 1. $taxonomy — Optional. (string) =>
'post_tag'
- The taxonomy for which to retrieve terms. Default post_tag..
Usage
if ( !function_exists( 'get_terms_to_edit' ) ) { require_once ABSPATH . '/wp-admin/includes/taxonomy.php'; } // The post id. $post_id = -1; // Optional. The taxonomy for which to retrieve terms. Default 'post_tag'. $taxonomy = 'post_tag'; // NOTICE! Understand what this does before running. $result = get_terms_to_edit($post_id, $taxonomy);
Defined (1)
The function is defined in the following location(s).
- /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;
- }