I want to get the selected tags using publish_post
hook, while publishing the post.
With below code, I can get only those tags which are already saved in the post. this will not work for new tags.
add_action( 'publish_post', 'post_published_notification', 10, 2 );
function post_published_notification( $ID, $post )
{
$post_tags = get_the_tags($ID);
if ( $post_tags )
{
print_r($post_tags);
}
}
I want to get the selected tags using publish_post
hook, while publishing the post.
With below code, I can get only those tags which are already saved in the post. this will not work for new tags.
add_action( 'publish_post', 'post_published_notification', 10, 2 );
function post_published_notification( $ID, $post )
{
$post_tags = get_the_tags($ID);
if ( $post_tags )
{
print_r($post_tags);
}
}
Share
Improve this question
edited Oct 15, 2019 at 6:24
Chetan Vaghela
2,4084 gold badges10 silver badges16 bronze badges
asked Oct 15, 2019 at 5:52
Prashant PatilPrashant Patil
1136 bronze badges
1 Answer
Reset to default 0if you want to get all selected tag in "publish_post" try below code. it will give you selected tag from post. remove wp_die("all Tags");
after verify that you can get proper tags on publish post.
add_action( 'publish_post', 'post_published_notification', 10, 2 );
function post_published_notification( $ID, $post )
{
$all_tags = $_POST['tax_input']['post_tag'];
if ( $all_tags )
{
echo "<pre>";
print_r($all_tags);
echo "</pre>";
wp_die("all Tags");
}
}
It will output all selected tags by comma separated like :
new10,new4,new5,new6,new7,new8,new9
Let me know if this works for you!