Execute set of commands while posting (9 posts)

  1. Asapcorp
    Posted 7 years ago #

    Hello all,

    Is there any plugin available to execute set of php statements while creating a post ?

    my concern is, while submitting a post, the user will submit a URL as a custom field and couple of other custom fields. I need validate the URL submitted by user whether it is broken or not, then accept the post.

    let me know if there is any existing plugins available or show me a way how to do it.

    BTW, i know little bit of php & mysql ;)

  2. Make your own plugin. It's easy.

    Also see this:

    Look carefully at the action hooks, especially the "publish_post" action.

  3. Asapcorp
    Posted 7 years ago #

    thanks. I have tried quickly and now I would like to know some more info.

    a. I would like to find the post id of the post I am submitting to.
    b. I would like to find the custom fields submitted by user. (for the post I am trying to publish)

    I already tried get_post_custom_values("mycustomfield") but it doesn't work.

    Thanks a lot :)

  4. The publish_post action passes the ID of the post to your function.

    function whatever($postid) {
    // $postid has the post id in it.

    Then, you can use get_post_custom_values('whatever',$postid); as well.

  5. Asapcorp
    Posted 7 years ago #

    thanks. i will give a try. :)

  6. Asapcorp
    Posted 7 years ago #

    okay. it works great. thanks for helping me. :D

    Now i am facing a new problem. it executes the function every time we publish the post. I mean if we edit the same post it executes the function again.

    Is there any way to execute only once ?

  7. There's six different statuses for posts:

    Whenever a post status changes, a OLD_to_NEW action occurs. So new_to_draft happens when you create a new draft, sort of thing.

    If you make five different hooks (all to your existing function), with all of the types going to_publish, then you can hook all the ways to publish a post for the first time. Like new_to_publish, pending_to_publish, etc.

  8. Asapcorp
    Posted 7 years ago #

    Thanks I will give a try during weekend. :D

    BTW, I have written a new plugin :D:D

    Thanks a lot for your help :)

  9. mschaefer
    Posted 6 years ago #

    I can't find any documentation for the OLD_to_NEW posts—can you please point the way?


Topic Closed

This topic has been closed to new replies.

About this Topic