Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [save-post]

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.

75 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
1answer
2k views

trigger save_post event programmatically

Is there a way to trigger the post saving or updating event in code? such as do_action('save_post', $post_id); The function here seems to imply that a WP_POST object needs to be passed in. Is there a ...
3
votes
0answers
79 views

What to use: wp_is_post_autosave( $post_id ) or DOING_AUTOSAVE?

I was doing some action on save_post hook, and noticed that there exists wp_is_post_autosave( $post_id ) function. How does it differ from DOING_AUTOSAVE constant? If I want my action not to run ...
2
votes
0answers
138 views

wp_insert_post_data filter not working correctly after upgrade to Wordpress 5

I have the following code in a project. function vb_post_modified_date_update($data, $postarr) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if (!empty($...
2
votes
1answer
82 views

save_post only saves meta data on second save

I am trying to use the save_post hook, but it is not working as intended: I want to save the Taxonomy (Region) with the ID 75 when the radio button 'wpcf-proprty_online' is 'y'. When I open the Post &...
2
votes
1answer
288 views

Get Post ID with insert/edit link

Hi I want to get the post ID from the post selected in the insert/edit link button. I would normally do: <a data-id="<?php echo $post->ID; ?>" href="<?php the_permalink();?&...
2
votes
1answer
80 views

Cron While Editing Post

I have a multi-author blog, on which there are two schedule cron functions. The first function moves all public posts in the pending status after 365 days: if( ! wp_next_scheduled( '...
2
votes
0answers
620 views

publish_post conflicts with save_post

my plugin has a save_post hook used to save the custom fields. now I add a publish_slider hook used to change a checkbox's status(slider is a custom post type). but it doesn't work properly. the ...
2
votes
0answers
1k views

How to manage saving custom field from Quick edit and Post Save using save_post action hook without colliding each other?

I's following Rachel Carden's tutorial on creating Quick Edit and Bulk Edit, and grabbed her full work from her github repo. I managed doing everything fine and I made a checkbox instead of radio ...
1
vote
1answer
23 views

How to change image atributes right before an image to be saved?

I have an installed plugin to import XML content, but it can't change some meta-data of the new image that will be saved. For example, I'd like to intercept the action of saving an image BEFORE its ...
1
vote
0answers
321 views

ACF (Advanced Custom Fields) not updating post or postmeta values

After changing the name of a ACF field, existing fields for some posts are not updating, but some are. Also, new posts are recorded correctly and can be updated. It's just that some of the old ones ...
1
vote
0answers
180 views

Getting gutenberg (WordPress 5) to save TInymce data?

I'm using this function to add a tinymce meta box: add_action( 'add_meta_boxes', function(){ add_meta_box( 'test_tinymce', 'Test TinyMCE', function( $post ){ $field_value = get_post_meta(...
1
vote
0answers
98 views

Support auto-save and revisions for custom fields

I recently read this tutorial about custom fields in WordPress and wrote a simple plug-in to provide a metabox with a set of input fields. I do not use the Meta Box plug-in promoted on the web site. ...
1
vote
1answer
234 views

Add category only if post has custom taxonomy category

I'm trying to add a category to a post that has a custom tax category applied. If the post has the custom tax category, it should also get a standard category. So the code below will add the standard ...
1
vote
0answers
311 views

Get updated meta value after post update or published (custom post type) using hook

function corp_210517_save_post($post_id, $post, $update) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } if( wp_is_post_revision( $post_id ) ) { ...
1
vote
0answers
24 views

Validate post checking if child term is assigned

For this particular case, all posts had to be a child term assigned to be published. I'm trying to hook on the "save_post" action, check the terms, return an error message if no child term is ...
1
vote
0answers
203 views

Can't find infinite loop cause

I am working on the below function which will eventually create a set of posts based on meta data entered into a "parent" post. I'm running into an infinite loop when hitting the save button, which I ...
1
vote
1answer
175 views

custom-meta-box checkboxes from loop won't save

I tried to create a custom meta box with checkboxes, generated from a loop of a custom-post-type. I found this example here on WP Development, but I can not figure out why the boxes won't save. My ...
1
vote
0answers
49 views

CPT Validation to not show “Post updated.”

Now this has been asked several times over on all WP forums, but how you change the success message? First, I know there are 2 choices for managing the error message: setting in the options and using ...
1
vote
0answers
591 views

Update post meta using save_post hook in multisite

I am trying to update a post meta field in a custom post type in Multisite. i am using the save_post hook to do so unsuccessfully. I don't know if the reason / cause is the multisite? or wrong use of ...
1
vote
0answers
429 views

Wordpress custom admin notice still displays after wp_insert_post_data validation

I am trying to validate post data before saving, specifically checking to see if an image exists within the first 750 characters of the post content. The code below works and display the admin notice ...
1
vote
0answers
292 views

How to notify specific users when i'm posting/modifying a new post

Here's what I'm trying to do... I'm trying to send new submissions only to contractors requested. Using Role Scoper, I can select only users who can access the new submission. However, I am looking ...
1
vote
1answer
329 views

Saving Custom Field Data before Publish

When creating a page or a post WordPress lets the content (title, body, featured image) be saved when using Ctrl + S. The Custom Fields do not save in the same way (in this case I'm using Advanced ...
1
vote
2answers
2k views

save_post custom post type ? $_POST not working?

i have this code. <?php add_action('add_meta_boxes', 'ct_meta_add'); add_action('save_post','ct_meta_save'); add_action('save_post','ct_parent'); // add meta functions function ct_meta_add() { ...
0
votes
0answers
13 views

Auto-Select Parent Category as Primary

I am using Yoast SEO Premium to handle the selection of Primary Categories. I am currently working with a Listing (listing) custom post type with a hierarchal taxonomy of Listing Category (listing_cat)...
0
votes
0answers
21 views

Save post as a draft if term of taxonomy not selected

I have a custom post type with metabox that contains form and few taxonomies in a side panel. Taxonomies are by default checkboxes, and at least one term of each taxonomy must be selected otherwise ...
0
votes
1answer
23 views

save button grayed out randomly

Hello wordpress community, we are facing the issue, that the save-button in wordpress is sometimes greyed-out (and stays that way). As far as we observed this, this usually happens on the auto-save. ...
0
votes
0answers
23 views

Updating failed message when a wp_insert_post function is hooked to save_post hook

I was creating a function which creates a new custom post type with the category or taxonomy name if it was created from the post editor. I am simply using the wp_insert_post function with the ...
0
votes
0answers
12 views

Save_post based on taxonomy

Lets say I have a taxonomy with 3 elements, A, B and C On save_post hook I would like to do some logic For example If user select A then do X on save_post If user select B then do Y on save_post ...
0
votes
2answers
77 views

Get Category in save_post Hook

in a class I have a function for save_post action. In this function I send an email. All this works except for querying the categories for that post: class _new_notifications { public function ...
0
votes
2answers
26 views

Custom post types saved as basic post

I made a custom post type filters for others post types. The slug is a concatenation like "filters-" . $custom-post-type. And the custom post type appears correctly in the menu : My problem is when ...
0
votes
0answers
35 views

How to get data from div?

Like when you call the hook 'save_post' to the content div on the page the create/edit post in Admin panel? Everything is correctly written in the second save function: $my_dom = new DOMDocument; $...
0
votes
1answer
36 views

Save_post acf data not updating category of post type

i am trying to assign multiple categories to my Custom Post Type using advanced custom field named 'cat'. But there is nothing saving to my categories. Any help? <?php // Add an action to run on ...
0
votes
0answers
49 views

update a custom field with the value of another existing custom field

I am trying to write a function to copy the value of an imported custom field (postalCode) to another custom field (wpcf-adres) when the post is saved or created. But i cannot get it to work, so there ...
0
votes
0answers
35 views

How do I save values from a foreach output on an options page?

I am creating a plugin that outputs a metabox on each page to be able to assign custom meta descriptions plus some other values. All of that works perfectly. However, I also have a "bulk editor" ...
0
votes
0answers
72 views

Post meta is not accessible within save_post hook

I am using this code to update post meta but it is not working. function run_when_job_published( $post_id, $post, $update){ $post_meta = get_post_meta($post_id); } add_action('save_post_jobs', '...
0
votes
3answers
959 views

Set Primary category using the Yoast SEO plugin

function set_primary_on_publish ($post_id) { global $post; $categories = get_the_terms( $post->ID, 'category' ); // wrapper to hide any errors from top level categories or products ...
0
votes
0answers
83 views

WordPress dosn't save page/post updates

Any suggestion what could cause the problem, that a WordPress site doesn't save any changes in one specific page? After making any changes in a page, it doesn't save the changes. However, from time ...
0
votes
1answer
170 views

save_post function keeps triggering: Warning: array_map(): Argument #2 should be an array… when restoring from trash

How to get a custom save_post function to return the default $post_id, $post, and $status for items with a post status of 'trash'? Everything I return, no matter which way I try, spits out Warning: ...
0
votes
2answers
128 views

generate random slug when adding taxonomy

I have created a custom post type called 'reports' to provide an easy method for providing monthly reports to specific people. I don't want users to have to login to view the reports and I also don't ...
0
votes
0answers
79 views

problem when uploading file by metaboxes

I want to upload pdf files via posts using metaboxes. I have this code: if ( is_admin() ) { add_action( 'load-post.php', 'call_MetaBoxClass' ); add_action( 'load-post-new.php', '...
0
votes
0answers
33 views

How to save post_status using action save_post?

I have a custom post status and i'm wondering if it's possible to save changes of post_status using action save_post? Sample codes would be great.
0
votes
0answers
81 views

How to stop post status from reverting to Published?

I have custom post types and custom statuses registered. The post status is updated from a custom drop down box that I have inserted into a metabox on the edit post screen. It works fine, however ...
0
votes
0answers
26 views

problem with admin panel

Absolutely new wordpress installation. I'm adding a new record, it is not added. Writes what is published, but when I go to the "all records" section - there she appeared, but the previous one ...
0
votes
1answer
21 views

Link two different post using there post_id in post meta

I have a frontend form through which users can create custom posts(events in my case). Now I am want to fetch all address data from that form and create a new post once that complete form is ...
0
votes
0answers
64 views

save_post doesn't correctly process function call with php class

I've written a class that outputs various JSON data from my postmeta. I'm able to call this within my theme on a template page. However, when it's inside my save_post it will not fire. I've put ...
0
votes
0answers
165 views

preg_replace style attr in $content and Editing post_content before saving

I`am trying to clean style attr from tags when saving posts and products but nothing happend. (I checked my regexp on https://regex101.com/) function filter_style_save($content) { $re = '/(<[^>]...
0
votes
0answers
147 views

Saving post meta

I'm not sure why my meta data isn't saving on 'save draft'. When I click save draft the data disappears. I think I've got it all right. I've run the code in the validator and all appears fine? ...
0
votes
0answers
145 views

How to get a post meta value and pass that to update_option when a post is created or updated?

When a user publishes or updates a post I want to get a post meta value from that post itself. Then I want to use update_option() to pass that value into the get_option() name. I've been trying ...
0
votes
1answer
981 views

Generate post title and permalink from custom field and post date

I have a custom post type with the following permalink structure /%match_season%/%match_team%/%postname%-%year%-%monthnum%-%day%/ %match_season% and %match_team% are taxonomies. The post type ...
0
votes
1answer
41 views

How to implement custom post type's users

I'm still a WordPress rookie and I'm trying to see what is the best approach to handle this. I have a website with about 10,000 users. I also have a Events post type and on each event detail page, ...