Try this…
add_action('post_updated', 'myfunction');
function myfunction( $post_id ) {
global $post;
if (!file_exists("/www/foo/blog/wp-content/uploads/" . $post_id)) {
mkdir("/www/foo/blog/wp-content/uploads/" . $post_id, 0777);
}
}
NOTE: Change from save_posts
to post_updated
which will stop the duplicate issue as it fires on “publish” only and not every time you hit add new
or update
etc.
NOTE: I verified this for you by testing the snippet above – all good.
NOTE: You can also use (wp_upload_dir() . $post_id, 0777)
if you want a path that is more transportable or if you are developing a plugin or theme for public use.
Related Posts:
- Update post meta within save_post action
- How can i take all ids from untrash_post action?
- Get page ID of page that is set as the posts page
- Is there a action hook for the “Empty Trash” button?
- Function to execute when a post is moved to trash .
- add action only on post publish – not update
- Are post ID’s reliable?
- Get current post id in functions.php
- How to validate XML-RPC post creation and cancel when needed?
- get all posts ID from a category
- Create posts on user registration
- Get the current post ID as a variable in Javascript
- Is post ID number always incremental n+
- How to publish a post with empty title and empty content?
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- How to add a “publish” link to the quick actions
- Action hook ‘wp’ firing twice… why?
- What to use: wp_is_post_autosave( $post_id ) or DOING_AUTOSAVE?
- Are all ID’s used unique?
- Better post meta efficiency?
- Count singular post views automatically
- $post->ID displays wrong ID
- How can I pass $post object to ‘save_post’ add_action?
- At my posts archive page, outside the loop, get_the_id() returns the top most post’s ID
- Showing random content / pictures from earlier posts in a sticky post?
- Have save_post write to database image meta [closed]
- Custom function for “Submit for Review” hook
- get post id in while loops outputting page id
- How can I display a specific user’s first published post?
- Undefined variable post_id in custom quick edit coloumn
- how “manage_posts_custom_column” action hook relate to “manage_${post_type}_columns” filter hook?
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- publish_post conflicts with save_post
- add_action not using ‘delete_post’ action with wp_delete_post
- Getting post id from wp_insert_post_data function?
- Does an article (post) id ever change?
- the_posts filter been called multiple time
- Get post id in wordpress action?
- How can i do something after head like adding a hook for after head but before post
- How to get the post’s parent ID?
- Can a page_id and a post_id be same?
- How to run a function when post is edited or updated using publish post action?
- Is there a better, more efficient way to get the post id outside the loop?
- Create cron job without a plugin?
- How to generate numbers indistinguishable for the IDs of the posts
- Getting current post ID in functions.php
- Buddypress activity id
- How blog page in WordPress works : blog page retrieve first post ID
- How to get post bulk edit action trigger and get edited post ids?
- Post-ID in url differs from $post->ID
- Why is my Blog Page ID == First Post ID?
- Get Meta Key Value While Saving Post
- current post with current author
- Is it possible to change post id for an already added menu item in WordPress?
- Adding custom fields to bbpress reply form
- Adding buttons to Add New Post and Add New Page
- Get ALL post ID’s export list (Only id’s. Php or sql not important )
- How to get next post ID?
- How to access $post from a callback function
- Search results posts_orderby and ID
- Updating post data on save (save_post vs wp_insert_post_data)
- Set static page/post from another blog on same network
- Copy post to separate database with “add_action(….)”
- Retrieve post ID from “querying” URL
- How to get a post’s content? [closed]
- Call Web Services on post first publish
- How to check if single.php has already called the_post_thumbnail function
- obtain the author id given the post id
- How to get ID of the page included with get_page()?
- How to I retrieve the ID from the Posts page?
- Crazy Question – Updating Post ID
- save_post hook is not called when post is saved
- What does WordPress do if I save a post without content/title? [duplicate]
- Why I can not I use the variable outside my function?
- Divs appearing everywhere in post content
- retrieve the oldest post id
- Prevent posts with certain post_meta to be edited
- How to check in functions.php if there is data in a WP_Query?
- Change post author without using wp_update_post()
- Automatically set post_parent value
- WP_Query custom field pass the post id
- Exists filter or action that change Add New Post link?
- Accessing Post ID Within Loop
- How do post IDs work in WordPress?
- Are post, page and category IDs unique to each other?
- The loop starting at a certain ID
- linking to post outside the loop
- Widget to show posts in the sidebar basing on its IDs
- Get a post’s ID
- Making posts permalinks consistent numbers
- How to get post id of last approved comment?
- How to get the post id (of the parent custom custom type) in a loop inside a widget?
- Actions to use when flushing cache (when posts are added / deleted / modified)
- Save / Update meta data as multidimensional array
- Is there a way to know when a page has been updated and do some action only once?
- Get post slug and match with menu item slug to change css
- Run a function when a custom post is update?
- WordPress Post ids big increment
- the wp_post_update isn’t working all the time
- Execute php after post save/update