• I configured a webhook to be called when a new post is published. This works fine for new posts created after having installed the plugin. For older posts that were already published, the webhook is triggered when they are updated.
    I understand that the plugin needs to set a meta value in the database to detect these duplicates. Is there any way to do this for old posts?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hi @salimhb – thank you a lot for your message.
    That’s actually a very interesting question.
    I checked on it and there are some ways you can make this.

    What you have to achieve is that you add the meta entry wpwhpro_create_post_temp_status to the post, which is already enough for it to be triggered.

    In case you use Advanced Custom Fields, I suggest adding a true/false field there for your posts, which contains the meta_key wpwhpro_create_post_temp_status
    Once you have done that and you check the trigger and save the post, it will run the logic again the post should update.
    This works as long as you have the Post Trigger Delay active. (If you are not sure about that, please check if the box for the Post Trigger Delay within the settings is unchecked.

    Hope this helps so far.
    If you need anything else, feel free to let me know.

    Thread Starter salimhb

    (@salimhb)

    Thanks @ironikus for the quick detailed reply.
    To understand correctly, I have a trigger on post_create and configured with the option “Trigger on initial post status change” set to “Published”.
    The aim is to only call the trigger, when a post is published.
    However, I don’t want it to be triggered again when an already published post is updated.

    If I understand you correctly, I should add the custom field “wpwhpro_create_post_temp_status” to such post and set it to true? This will prevent the webhook from being triggered again?

    Plugin Contributor Ironikus

    (@ironikus)

    Hey @salimhb – thanks for the additional details – Based on the given information of your first message, I based my reply on the procedure of how you can achieve that old posts are triggered as well for their initial post status change.

    Your newly given information changes the whole setup again – here are some information dedicated to your last message:

    Even if you update an old post, this post does not trigger the create_post webhook again since it is already existent.
    The meta value we set is (and can) only be set once a post is created. If this wasn’t the case, the post won’t receive any meta value.
    Also: Once the post was successfully triggered, the meta value gets removed again from the DB.

    Based on your given information, this can only mean one of the following conditions:

    1. You use the Send Data On Post Update trigger to send data as well (Then also old posts will be triggered)
    2. The old post has the meta entry wpwhpro_create_post_temp_status
    3. The post that is triggered is a revision – to check against that, please only select the posts you want to trigger the webhook on within the webhook URL settings.

    Hope this helps so far.
    If you have further questions, feel free to reach out again.

    Thread Starter salimhb

    (@salimhb)

    That’s strange, I have only enabled the “Send Data On New Post” trigger.
    I’d appreciate it if you check my settings from these screenshots: https://www.dropbox.com/transfer/AAAAAONCwpiHF2i8LDUENe_3dVneCPor167x-W9-AGjM3R-_OmEJd8M

    I also added this code snippet to my theme’s functions.php to support wpml https://gist.github.com/Ironikus/fa84d28c5059b172b150fa27d7ac0622#gistcomment-3203122

    Plugin Contributor Ironikus

    (@ironikus)

    Hey @salimhb – thanks for the additional details.
    From the screenshots I can tell that everything looks correct.

    With the given information, I can sure confirm that condition one and three are not met from my last message.

    Can you confirm that none of the posts before have the meta entry wpwhpro_create_post_temp_status set?

    The WPML code shouldn’t affect the logic itself, but they bring me to another guess:
    Can you please check if the posts that are sent over (once you update an old post) are translations?

    I’m asking this since depending on your settings, WPML copies posts in case they are not available within a language. That can cause to fire the trigger too since it basically creates a new post.

    I suggest checking against the post id and the language of it that fires since this might be an indicator.

    If this does not solve the problem, please also check the other plugins you have installed. From the past I know that some plugins are deleting and recreating posts on their behalf.

    If you need anything else, please let me know.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Don’t trigger webhook when updating old published posts’ is closed to new replies.