• daubit0daniel

    (@daubit0daniel)


    When using the transition_post_status hook, i cannot get the tags of an post. I tried using These functions get_the_tags and wp_get_post_tags but niether work. I just simple get an empty array. Always. No matter how many tags I provide with the new post.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    I think the taxonomy stuff is the last thing to happen during the save. You would need to research the code to see which happens first, the tags added or the post status transitioning.
    You might have to find a different hook to do what you want.

    Moderator bcworkz

    (@bcworkz)

    Joy is correct in that taxonomy terms are handled very late, but your action actually does fire after the terms are set. However, DB writes are relatively slow and PHP code keeps on executing in the mean time, so you encounter a race condition where the DB data you want isn’t yet available when your action callback executes. We used to be able to get current term data from $_POST, but because the API is often used to save term assignments, this is no longer reliable.

    A long way to say Joy’s suggestion to find a different hook is correct. Find a hook that fires when the terms are assigned to a post, where the term data is passed to your callback so you don’t have to get them through other means.

    What terms are you trying to get and what do you wish to do with the information? Maybe I could help you find a good hook.

    Thread Starter daubit0daniel

    (@daubit0daniel)

    I’m trying to send an email with the post Information (Title, thumbnail, Text, post url, …) After a post is first published. To trigger the sending of the email, the post should have a specified tag assigned to it.

    I’m having the same trouble with the thumbnail image. I guess thats caused by a similar issue?

    I tried the publish_post hook too, but it doesn’t seem to work either.
    I would appreciate if you could help me find the right for this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Cannot get tags within transition_post_status hook’ is closed to new replies.