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 ...
2
votes
0answers
53 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
113 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
70 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
273 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
79 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
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
0answers
162 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
1answer
232 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
302 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
187 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
173 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
584 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 ...
1
vote
0answers
47 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
563 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
417 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
320 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
14 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
41 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
35 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
40 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
194 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 ...
0
votes
0answers
27 views

Link of cpt error when I have duplicate post titles

I have a problem. when I have duplicate post titles: Post 1 titles "Story" link: https://domain.com/story-1.htlm Post 2 titles "Story" link: https://domain.com/story-1-2.htlm and cpt name "chap", ...
0
votes
0answers
33 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
1answer
47 views

Execute function after a post has been published

I'm using a post crawler on my website that pulls articles from other websites and automatically publishes them on my website. During that process, it checks for any video embed codes; if they exist, ...
0
votes
0answers
69 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
0answers
70 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. ...
0
votes
3answers
643 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
64 views

Save & Share Cart for WooCommerce cart title use in cart page

I'm using save and share cart in woocommerce site and I create a page to load all saved carts title since plugin creates a posttype and I load each saved cart using same url plugin used in a email ...
0
votes
0answers
71 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
163 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
120 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
74 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
32 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
77 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
18 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
61 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
159 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
131 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
133 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
2k views

Update post meta within save_post action

I'm currently trying to update a post's meta value within the save_post action. The problem with this is that it gets overwritten immediately. I've been banging my head on this problem for several ...
0
votes
1answer
885 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, ...