save_post is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email. The data for the post is stored in $_POST, $_GET or the global $post_data, depending on how the post was edited.

learn more… | top users | synonyms

3
votes
2answers
4k views

Retrieve 1st image in post and set it as featured image, when post is saved/updated

I need to set a featured image for every post I publish. So, when a post is published/updated, the script would scan the post for the first image using a script like this: // Get URL of first ...
5
votes
4answers
5k views

Prevent post from being published if custom fields not filled

I have a custom post type Event that contains a starting and ending date/times custom fields (as metaboxes in the post edit screen). I would like to make sure that an Event cannot get published (or ...
2
votes
1answer
1k views

Check before publishing, if already exist post with current custom field value

I have a custom post type with only 3 custom fields in it. $post_types = get_post_meta($post->ID,'post_types',true); $post_taxonomies = get_post_meta($post->ID,'post_taxonomies',true); ...
10
votes
3answers
6k views

Passing error/warning messages from a meta box to “admin_notices”

I have a simple meta box that updates the post custom fields (using update_post_meta()). How can I send a error or warning message to the next page after the user publishes/updates the post and ...
14
votes
1answer
5k views

Why does save_post action fire when creating a new post?

I'm surprised by the fact that my function that I've tacked onto the save_post action fires when I click the "New Post" link in the Admin Dashboard. Note - this is before I've pressed Save or Update, ...
6
votes
2answers
4k views

Set custom messages for post update/save

I am trying to make a custom message instead of the default message when i save a post, does anybody know how to do it!
20
votes
6answers
11k views

Add validation and error handling when saving custom fields?

I have a function that defines a custom field on a post type. Say the field is "subhead". When the post is saved, I want to do some validation on the input, and display an error message on the post ...
7
votes
2answers
2k views

Return $post_id when DOING_AUTOSAVE?

I see the following pattern over and over, on this site and on other places: add_action( 'save_post', 'wpse14169_save_post' ); function wpse14169_save_post( $post_id ) { if ( defined( ...
2
votes
2answers
280 views

How to force function to run as the last one when saving the post?

I don't know how to force this function to run as the last function after all other save things from WP are executed. This is my current code in my plugin: add_action( 'save_post', 'do_custom_save' ...
0
votes
1answer
149 views

Minimum Word Count Before A Post Can Be Made Pending Review

I'm looking for a way to check that a post has a minimum word count before allowing it to be sent for review (added to the pending post status). Below is the code I have: if ...
3
votes
4answers
3k views

Force post slug to be auto generated from title on save

I'm running a property site where many properties are sold in apartment blocks. Because of this what the content editors do is create a post/property with all the details and then use a duplicate ...
4
votes
2answers
2k views

How to avoid infinite loop in save_post callback

I have been using this site alot for solving my problems, but this time I did not succeed in finding and answer for my problem. I get and infinite loop when using wp_update_post inside a function ...
2
votes
4answers
4k views

Check for update vs new post on save_post action

Is it possible within the save_post action to determine whether it's a new post being created or an existing post being update?
0
votes
1answer
335 views

Custom field values get deleted

I created a custom post type:products which also has custom fields: price & shipping. Occasionally, if I leave the edit product window open or refresh it, I lose the values inside price and ...
1
vote
1answer
1k views

Save selected item from dropdown menu in a meta box as a metadata value for a custom post type

I have been beating my brains on this one for days now and my Google-fu is failing me. I have created a custom meta box with a dropdown menu that lists all of the terms from a custom taxonomy. What I ...
0
votes
2answers
1k views

update_post_meta() not working in save_post

I have added some text input fields to metabox in my custom post. Now whenever I put some data in those text fields in admin panel and click 'save', all data vanishes. Here is the code: <?php ...
5
votes
2answers
3k views

Why won't my metabox data save?

I have a custom post with a lot of meta boxes. I recently tried to add some dynamic metaboxes, using this question: Create more Meta Boxes as needed I managed to get the metaboxes to add nicely, the ...
2
votes
2answers
2k views

Using save_post to replace the post's title

I am using custom posts, and in these, I don't a need for the title. This causes Wordpress to set the titles of my posts to "Auto Draft". I'd like to change the title's value to something else, ...
1
vote
1answer
75 views

Change 2 fields in the post depending on the 3rd field before save

I have a custom content type called cards. I have 3 custom meta fields called: my_cards_activity (select field type; options 0 and 1) my_cards_user (select type; many options) my_cards_datetime ...
3
votes
2answers
742 views

Submitting posts from the front end - sanitizing data

I have a form that allows any registered user to submit a post (it's a custom post type - forum related), and I'm using wp_insert_post() to insert it into the db. From what I've seen in this function ...
1
vote
1answer
1k views

How can i create a function to get youtube video time

Tom J Nowell posted this code to help me retrieve the YouTube video time. Functions // function to parse the code from the URL function parse_youtube_video_id_from_url( $video_url ) { ...
1
vote
3answers
2k views

Conflicting save_post functions when passing the post id and saving custom meta boxes for different post types

Post save functions are conflicting with each other when adding them to the save_post action hook. 2 different custom post types with 2 different (one for each post type) custom meta boxes. I'm ...
0
votes
1answer
176 views

Second select list values are not saved after clicking update

I have a select list in a metabox which value is saved successfully after clicking "Update" when editing post. Of course, the values are custom taxonomies. But i don't know how to add another select ...
0
votes
1answer
234 views

Why does not my metabox save?

I know there are many questions about variants of this, but I have not been able to find an answer. I have a metabox on the post type page, containing nothing but a checkbox. It seems like it won't ...
0
votes
1answer
1k views

update_post_meta and update_field ony working when saving the post

I use Advanced Custom Fields (ACF) to store data in a custom field. I had latitude and longitude information stored separately, but I they need to be in one custom field so I made the function below. ...
0
votes
1answer
285 views

Update Custom Field on Imported Post Creation

So I've created a function that updates several custom fields in a post when the post is created. The idea is to sanitize this information so that I can easily use it for other purposes. The ...
0
votes
1answer
1k views

Is there an easy way to AJAX-ify saving of post?

We have a plugin that allows us to manage custom post types and we'd like to add AJAX functionality in saving, editing, and deleting posts. I couldn't find similar problems in the internet so I'm ...
0
votes
1answer
1k views

prevent post submission

I'm using a meta-box for custom post type. I have three problems: WP seems to run the function that I attached to the "save_post" action, every time a new post is opened for editing or reloaded. Is ...