The get_tags_to_edit() WordPress PHP function retrieves a comma-separated list of tags available to edit for a specific post.
Usage
get_tags_to_edit( $post_id, $taxonomy = 'post_tag' );
Parameters
$post_id
(int) – Required. The ID of the post for which to retrieve the tags.$taxonomy
(string) – Optional. The taxonomy for which to retrieve terms. Default is ‘post_tag’.
More information
See WordPress Developer Resources: get_tags_to_edit()
Examples
Display a list of tags to edit for a specific post
This example retrieves and displays the list of tags available to edit for a post with the ID of 42.
$post_id = 42; $tags_to_edit = get_tags_to_edit( $post_id ); echo 'Tags to edit: ' . $tags_to_edit;
Retrieve a list of categories to edit for a specific post
This example retrieves and displays the list of categories available to edit for a post with the ID of 42.
$post_id = 42; $taxonomy = 'category'; $categories_to_edit = get_tags_to_edit( $post_id, $taxonomy ); echo 'Categories to edit: ' . $categories_to_edit;
Check if a post has specific tags to edit
This example checks if a post with the ID of 42 has the tags ‘travel’ and ‘adventure’ available to edit.
$post_id = 42; $tags_to_edit = get_tags_to_edit( $post_id ); $tags_array = explode( ',', $tags_to_edit ); if ( in_array( 'travel', $tags_array ) && in_array( 'adventure', $tags_array ) ) { echo 'The post has both "travel" and "adventure" tags.'; } else { echo 'The post does not have both "travel" and "adventure" tags.'; }
Display the number of tags to edit for a specific post
This example retrieves the number of tags available to edit for a post with the ID of 42.
$post_id = 42; $tags_to_edit = get_tags_to_edit( $post_id ); $tags_array = explode( ',', $tags_to_edit ); $tag_count = count( $tags_array ); echo 'The post has ' . $tag_count . ' tags available to edit.';
Display a list of tags to edit for all posts
This example retrieves and displays the list of tags available to edit for all posts.
$args = array( 'posts_per_page' => -1, 'post_type' => 'post', ); $posts = get_posts( $args ); foreach ( $posts as $post ) { $tags_to_edit = get_tags_to_edit( $post->ID ); echo 'Post ID ' . $post->ID . ' tags to edit: ' . $tags_to_edit . '<br>'; }