posts - Wordpress get tags in “publish_post” hook

I want to get the selected tags using publish_post hook, while publishing the post.With below code, I can get only those

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
Add a comment  | 

1 Answer 1

Reset to default 0

if 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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745081226a4610137.html

相关推荐

  • posts - Wordpress get tags in “publish_post” hook

    I want to get the selected tags using publish_post hook, while publishing the post.With below code, I can get only those

    11小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信