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
1 answer
343 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' ); ...
Piotr Kucułyma's user avatar
1 vote
1 answer
172 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"> ...
Adnan's user avatar
  • 51
0 votes
2 answers
7k 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 ...
Dylan Smit's user avatar
2 votes
1 answer
670 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 ...
David Labbe's user avatar
0 votes
1 answer
40 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(){ $...
AmintaCode's user avatar
1 vote
1 answer
275 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 ($...
aitor's user avatar
  • 605
0 votes
2 answers
2k 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 ...
Gregory Schultz's user avatar
1 vote
1 answer
2k 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"]=> ...
RobbTe's user avatar
  • 242
6 votes
5 answers
6k 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 ...
Ben H's user avatar
  • 363
3 votes
1 answer
1k 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 ...
Shane's user avatar
  • 68
0 votes
0 answers
286 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 ...
gintsg's user avatar
  • 121
3 votes
1 answer
202 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 &...
parvaneh's user avatar
0 votes
2 answers
734 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 ...
Zeth's user avatar
  • 858
1 vote
0 answers
36 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
Gio Gra's user avatar
  • 11
0 votes
1 answer
312 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: ...
Jonathan Stegall's user avatar
0 votes
1 answer
503 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( '...
Michael Rogers's user avatar
3 votes
3 answers
3k 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', '...
BenB's user avatar
  • 795
0 votes
1 answer
276 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: ...
SHA3.org's user avatar
  • 119
0 votes
1 answer
220 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 ...
dudieboy71's user avatar
1 vote
1 answer
464 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 ...
SHA3.org's user avatar
  • 119
1 vote
3 answers
3k 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 ...
erolha's user avatar
  • 25
2 votes
1 answer
9k 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;...
Dawn's user avatar
  • 43
0 votes
2 answers
376 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 ...
Jared Wilcox's user avatar
0 votes
0 answers
131 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', '...
saeid ezzati's user avatar
0 votes
1 answer
2k views

Save meta data with post, Without using any plugin [closed]

I have a post type in which I need to save price with each item. Please, suggest how can I create meta-field in my post type, without using any plugin?
Saeid Dadkhah's user avatar
0 votes
0 answers
58 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.
Amenadiel17's user avatar
0 votes
0 answers
167 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 ...
Amenadiel17's user avatar
2 votes
1 answer
2k views

Check if the value of a field has changed on save_post

I have a custom post type where the user can set a video 'url' custom field. I need to download meta-data about the video (e.g. title, description, thumbnail) and store it along with the rest of the ...
GuitarExtended's user avatar
1 vote
1 answer
3k views

Set the value of custom field when post is published or updated

I'm trying to set the value of custom fields when a custom post type ('film') is published or updated. The end goal is to get meta-data from an API based on a URL field when the post is published or ...
GuitarExtended's user avatar
0 votes
0 answers
27 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 ...
Marat Petrov's user avatar
1 vote
4 answers
4k views

Call add_action() in function wordpress

I have a problem with a WordPress hook. I want to call an action in another actions callback, but it doesn't seem to work. I want to call add_meta_tag action only if the page is saved. This is what I ...
Skatox Nike's user avatar
0 votes
1 answer
364 views

save_post affect creation and deletion

I wrote a little bit of code to update the post name and slug (of my cpt) when saving. This is working nice when I update a post. I just noticed theses few lines are affecting the creation and ...
Steven Roh's user avatar
0 votes
1 answer
37 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 ...
inrsaurabh's user avatar
0 votes
0 answers
159 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 ...
Chris Stage's user avatar
3 votes
2 answers
3k views

Get updated meta data after save_post hook

I am trying to get the updated value of a piece of meta when a post is saved (custom post type) but when I try to grab the updated data on the save_post hook, I get the previous data instead. I tried ...
Eckstein's user avatar
  • 1,099
1 vote
2 answers
2k views

Add meta field after post has been published

I'm trying to add a custom field of event_month when a post is published or saved. I'm using the save_post action and getting the contents of a custom field containing the date and trying to store ...
Neil K's user avatar
  • 111
0 votes
1 answer
571 views

Dynamically set taxonomy term and show admin notice on post save

I have a taxonomy of "date" listing all months of the year. And I have a custom field of "start_date". I would like to update the 'date' taxonomy dynamically so the user doesnt need to click both when ...
mattbru's user avatar
  • 75
1 vote
1 answer
345 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 ...
Lindsay Westcott's user avatar
0 votes
0 answers
346 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 = '/(<[^>]...
Karin Kador's user avatar
0 votes
0 answers
221 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? ...
Ollie's user avatar
  • 81
1 vote
1 answer
465 views

Update post meta value as date difference between two fields

I have this code which is displaying the difference in days between two custom fields <div class="distance"> <?php $date1 = get_field( 'date_start', false, false ); $date1 = new ...
joelybristol's user avatar
1 vote
1 answer
341 views

How to inform the user that the save was not successful?

When saving a post, i have a meta box in which the user must put something. If the user input is something when i do not accept, how will i tell him? add_action('save_post' , 'my_save_metaboxe_data');...
Shake-the-World's user avatar
0 votes
1 answer
740 views

Custom Post Type Metadata Not Saving

I created a client profile custom post type and have started creating the meta boxes and such for users to enter in information. While all of that seems to be working fine, when I go to save the ...
Cedon's user avatar
  • 1,659
0 votes
1 answer
45 views

Post editor doesn't save embed media [closed]

I'm facing weird problem - I'm trying to save embed media to post in different computers and it doesn't work in all of them. We do the same process (insert -> media -> embed -> youtube code), and in ...
RonZ's user avatar
  • 101
0 votes
1 answer
65 views

Stripping URLs & Email from post submissions

I want to prevent users posting in this instance of WordPress from submitting URLs and Emails in posts. I'm trying to do it via Regex but I'm not sure if I'm writing the Regex incorrectly because it ...
Tanner's user avatar
  • 17
1 vote
0 answers
417 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 ) ) { ...
Rituparna sonowal's user avatar
0 votes
1 answer
1k views

Why not fire the save_post event?

World! Why not fire the save_post event? function action_function_name_13( $content ) { $content = '<div>' . $content . '</div>'; return $content; } add_action( 'save_post', '...
Pavel V's user avatar
5 votes
2 answers
8k 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 ...
TurtleTread's user avatar
0 votes
2 answers
3k views

save_post hook is not called when post is saved

In WordPress whenever new blog post is created all post details need to be send to third party API. I'm using save_post hook for this but not sure whether it's getting called or not This is what I've ...
Parth Goswami's user avatar
0 votes
2 answers
87 views

detect when a custom post is cretaed for the first time

I have a custom post type no_resume and when a new post is created in it and a meta that is job_category is assigned to it I want to perform a function in which a mail will be sent to all the user ...
apoorv's user avatar
  • 57

1 2
3
4 5
8