0

I've got a custom php file that I want to call every time someone publishes a new post. How would I go about doing that? Can I write it into the functions.php of my theme?

1
add_action('publish_post', 'call_my_php_file');
function call_my_php_file($post_id){
  require_once("path/to/file.php");
}
  • so I can drop that into functions.php? nice! – Ghost9 Jan 13 '11 at 2:15
  • I must not be doing something right as it doesn't appear to be firing.... – Ghost9 Jan 13 '11 at 2:36
  • if you're writing something to the screen, you won't see it because you get redirected after this action is executed. To see if your code works add a die(); after require_once... – onetrickpony Jan 13 '11 at 2:39
  • Ok i used your die command and it is running the script... now the problem is that I don't know where the xml is being generated that the script is making. the php that is. It normally saves it to the folder it's in, but I don't see it. – Ghost9 Jan 13 '11 at 2:46
  • ah ha! It's in the admin folder. so now I just need to figure out how to set the path for the save location. Thanks! This is awesome. From this I can make it so it updates on trash and update post as well. I think... – Ghost9 Jan 13 '11 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.