WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I having a problam with my wordpress plugin. The plugin does whenever new post has been published, it will automaticly create a new file with that post content.

this is my code

function example($post_ID) {
    global $post;
    $content = htmlentities(get_post_field('post_content', $_GET['post']));
    file_put_contents(dirname(__FILE__) . '\myFile.txt', $content);
add_action('publish_post', 'example');

But when i change the code some think like this. this will working

file_put_contents(dirname(__FILE__) . '\myFile.txt', "Some string here");
share|improve this question
If you want a question migrated, ask the moderators. I flagged your first question on SO – stackoverflow.com/q/10338875/299509 – for migration. – toscho Apr 27 '12 at 10:50
up vote 1 down vote accepted

Where you pass post id ?

 $content = htmlentities(get_post_field('post_content', $post_ID));
share|improve this answer
Oh my god.... WOW... finaly it works... thanks a lot man.. u saved my time. :) – Mifas Apr 27 '12 at 11:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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