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.

Filter by
Sorted by
Tagged with
0
votes
1answer
19 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
15 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
1answer
17 views

Run a function on all posts

I have a function where I am counting letters in a title and adding that _product_meta_title key, everything is working fine when I am adding a new product but I have 500 products that don't have this ...
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
24 views

Force user to write excerpt before saving post? [duplicate]

Is it possible, in functions.php, to force users by default to write an excerpt before they can save a post? And ideally, would it be possible to make this mandatory in only certain post categories?
0
votes
1answer
31 views

save_post() on Menu Save

When the wordpress menu is saved in the backend, functions hooked on to save_post() run. Is there a way to make these run only when singular items are saved, and not when the menu is saved?
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
1answer
21 views

Mutiple Select only POSTing 1 value

In a custom post type edit form, I have a select marked as multiple to allow multiple items to be selected: <select multiple size="6" name="product_ids"> <option value="71">First</...
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
48 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
1answer
119 views

Create post revision on slug change

I'd like to be able to track changes in the slug / post_name field of the post. I've tried using wp_save_post_revision(...); if I detect a slug change, but according to this page wordpress only ...
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 ...
1
vote
1answer
31 views

Check if post is added manually or through wp_insert_post()

I might not be thinking this right but here is my situation: I have a custom post type called events. Some of my events are imported from an API and inserted through wp_insert_post() (in a plugin), ...
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', '...
1
vote
0answers
163 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(...
2
votes
0answers
116 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($...
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
127 views

Wordpress 4.9.8 doesn't save if content has style="

Wordpress 4.9.8 when I save a draft/publish return me an error: Gone The requested resource /wp-admin/post.php is no longer available on this server and there is no forwarding address. Please ...
0
votes
1answer
55 views

On save_post need to wp_insert_post and save partent post id to child post and child post id to parent post

I'working on plugin for custom post types and it's metadata etc. Everything is fine so far but now I need to extend this plugin - I need to create one extra the same custom post on save/edit post when ...
0
votes
1answer
54 views

wp_insert_post inside save_post adds wrong metadata to inserted post

I have code for saving metadata for Student post_type. While saving metadata I also want to add separate posts for each payment in payments array: add_action( 'save_post', 'save_student_meta' ); ...
1
vote
1answer
38 views

Confusion regarding Nonce & using it in Custom Columns for Saving Checkbox Value to Post Meta

I believe there are multiple ways to use nonce. Recently I've used wp_nonce_field('any_nonce_value'); which creates a <input type="hidden" id="_wpnonce" name="_wpnonce" value="111bc61eba"> ...
0
votes
3answers
649 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 ...
2
votes
1answer
261 views

WordPress Gutenberg get page template value when post updated?

I need to get the page template name when the post is saved. It fails in save_post hook as $_POST('page_template') is not available. Gutenberg saves post via the REST API and uses ...
0
votes
1answer
26 views

How to register a widget when saving a post?

I've tried to solve my problem in the simplest way, but it doesn't work: why? function createNewWidgetSavingAPost($post_id) { add_action( 'widgets_init', function(){ $...
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 ...
1
vote
1answer
47 views

Write automatic title at save_post (infinite loop)

I want to write the post title with the content of a custom field $sentence_number, this way: add_action('save_post', function ($title, $post_id) { $post_type = get_post_type($post_id); if ($...
0
votes
2answers
251 views

WordPress function saves a post twice and updates all posts

I'm having a problem with a custom function. This function counts the post and assigns a number to that post. It then saves the number to a custom field and then updates the permalink to the post. My ...
0
votes
1answer
300 views

update_post_meta() with a modified array?

When in wp-admin I want to manipulate one value of an array and then update the post_meta with this array. My array looks like this: 1285 array(1) { [0]=> array(2) { ["description"]=> ...
1
vote
3answers
637 views

Unable to prevent function using save_post firing twice

I am using save_post for a function to send an email when a post is updated by a user. This is firing twice and I am aware this is due to the post revisions and autosaves. I have tried to prevent ...
2
votes
1answer
172 views

Action 'save_post' not working for quick edit

I have read other answers to similar questions but none of them solved my problem. This code works great in Editor but on Quick Edit or Bulk Edit it does not appear to fire at all. What am I doing ...
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 ...
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 &...
0
votes
2answers
143 views

Can't add_action to 'save_post' and get it to fire

I'm trying to add an action every time someone presses the 'Publish'-button. I've made this function: function custom_set_category_on_cpt( $post_ID, $post, $update ) { echo '<p>This does not ...
1
vote
0answers
23 views

Set default value field meta_Value [closed]

I need to have in the woocommerce products always a present SKU value equal to the value of the post_id. Is there a code that allows me to solve the problem? thank you
0
votes
1answer
103 views

Custom post type meta fields missing on save_post_type

I maintain a plugin that sends selected WordPress data to an external REST API (Salesforce, in this case) when matching objects are created, updated, deleted. For example, post works like this: ...
0
votes
1answer
102 views

save_post hook to add terms getting deleted when using bulk edit

i have a function to automatically add the first letter of each post title as a term on a taxonomy called "index". This is the code: function save_index( $post_id ) { if ( defined( '...
2
votes
3answers
495 views

WP Rest API - Upload media without saving attachment post

I need to hook after file uploaded to server, get the file path, and then prevent WordPress from saving the attachment post. I found this filter add_filter('attachment_fields_to_save', '...
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
1answer
85 views

update_post_meta not working in foreach

To avoid adding post meta values one at a time (and reduce repeat code in my theme) I wrote a simple class to store all the options so I can iterate through. The class works fine and constructs an ...
0
votes
1answer
77 views

How to auto-update child posts whenever the parent post is updated?

To clarify, this question is merely on how to "save" or "update" a child post when the parent post is saved. Nothing more. Hello to all of you brilliant and wonderful people. I need to auto-update ...
1
vote
3answers
531 views

Clear cache on post of one type when something happens to post of other type

EDIT: Based on @TimHallman's answer I have a follow-up question, please see the bottom of this post. I am trying to do something that is way over my head and the more I think of it, the more ...
1
vote
1answer
2k views

WordPress turns HTML code to HTML entities

I created a new wordpress page and added this into the Text tab (NOT the visual tab. The visual tab is disabled): <div></div> When I click Publish, the code turns into this: &lt;...
0
votes
2answers
121 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', '...