Skip to main content
The 2024 Developer Survey results are live! See the results

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
1 vote
1 answer
35 views

Why would I get a "Trying to access array offset on value of type bool" warning when using "metadata_exists()" in save_post?

When saving a post that is a custom post type (in the example, 'my_cpt'), I'm trying to check if a specific piece of metadata exists for that post. I'm using this exact same code on another site (...
Scott H's user avatar
  • 31
0 votes
1 answer
20 views

Show admin notice if metabox field is empty during save post

Who can help me a little. I try to get an admin error notice if a metabox field is empty during save post. Wordpress refresh the page after saving so the hook admin_notices does not work. Here is my ...
RickB's user avatar
  • 1
0 votes
0 answers
9 views

update ACF field when saving post on back office

I am trying to update the value of a custom field (order) inside a POST when it is saved on the back office. If my status is Sold, I want the value of order to be 3. Everything is working smoothly ...
david simon's user avatar
0 votes
1 answer
10 views

Custom fields empty after refreshing page

I have added some custom fields to the Gutenberg editor, the purpose is getting these custom fields loaded in the custom-post-type. Thats is all working, I was able to get the custom-fields in the ...
Brango's user avatar
  • 1
1 vote
2 answers
69 views

Generate Post Title From ACF Fields on Custom Post Type

I have tried a few versions of the code to get this working and seem to come up with a couple of errors either way. I am using ACF for the fields and adding the below code to the themes functions.php ...
Craig Watson's user avatar
0 votes
2 answers
49 views

Check if new post or update before save_post action

I want to use save_post on an update for an existing post and also for a new post, but I want 2 different "priority" on the save_post action. So, I can't check if it's an update into ...
John Pls's user avatar
1 vote
2 answers
100 views

How to run this plugin every time a post is saved?

So far this is what I have... I'm new to developing plugins so I'm not sure how to make a plugin run code on a post save. I know that this would likely work if it was added to the post.php page but I ...
Cody King's user avatar
0 votes
1 answer
36 views

Webhooks - Differ between new/existing updates

I'm currently trying to work with webhooks without using any plugins, and I'd like to avoid them if possible. The webhook should be triggered when a change is made to the Custom Post Type "event.&...
Björn's user avatar
  • 1
0 votes
1 answer
602 views

How to automatically update ACF field value every year?

I'm using ACF in my custom post type and I have 2 numeric fields: one for Birth year and another for Age. I want to update the age field automatically based on the birth year field value. I found out ...
Adriana Leites's user avatar
1 vote
1 answer
782 views

ERR_CONNECTION_RESET on post save or add media

About a year ago the site was moved to another host (same domain name). Every time I attempt to save a post, page or upload media, I'm immediately sent a connection reset error (This webpage is not ...
Alex Gubin's user avatar
1 vote
0 answers
32 views

Resaving posts to update static blocks

I changed markup in my custom static block and now I have to resave custom posts where I use them in order to update what is shown in the front. I tried to automatise procedure by using wp cli command ...
Lovor's user avatar
  • 951
0 votes
1 answer
79 views

How do I set a custom post type Category after import using wp_set_post_terms

I'm importing Events from a Salesforce Event Manager into WordPress, specifically into the The Events Calendar. The Events Calendar creates a CPT called Events. It also has its own Categories, which ...
Mikey B's user avatar
0 votes
1 answer
254 views

Set post status to draft after validating post meta values in save_post hook

I have some custom meta values to a custom post type ('event'). The custom post type is displayed in the admin and the custom meta fields are appearing fine. I am using save_post_{$post->post_type} ...
sariDon's user avatar
  • 265
0 votes
1 answer
369 views

Save_Post change Custom Post Type Post title to post id number

I have a Custom Post Type with the slug of "sightings". I do not need a post title, so I have removed the functionality - but now the posts are being saved as (no-title). I read about the ...
Nebin Esquire's user avatar
1 vote
1 answer
148 views

Get category of post inside save_post hook

I don't have much experience with hooks in WordPress so i have found a problem who don't look too difficult, but i can't find the answer. In my project i have a metabox who will get the content after ...
Matheus Ribeiro's user avatar
0 votes
0 answers
24 views

How to use wp_set_object_terms depending on page ID?

The function to set custom term works fine. add_action( 'save_post', 'set_custom_term', 30, 2 ); function set_custom_term( $post_id, $post ) { wp_set_object_terms($post_id, 'guitar', 'instrument',...
Kim Caspe's user avatar
0 votes
1 answer
33 views

UI does not show correct Slug after modified using save_post action

When a WP user creates a new Post the default behavior is that the Title is used as the basis for the Slug which forms a major part of the URL/Permalink. I am changing this default behavior. My code (...
donohoe's user avatar
  • 161
0 votes
1 answer
121 views

Wp doesn't save meta box data

My WP doesn't save my meta box data. I see the metabox and the field, but the data doesn't saving. Somebody could help me? Thank you. This is the code: // 1. Metabox létrehozása function my_meta_box(){...
Eszter's user avatar
  • 1
0 votes
1 answer
232 views

get_the_terms inside save_post gives old terms

When I use get_the_terms inside save_post, I get the old taxonomy terms. This is something that I would expect from pre_post_update, but why does it happens to save_post ? And, more important, how to ...
Tahi Reu's user avatar
  • 298
0 votes
2 answers
198 views

Save frontend submission form field as custom field

I use plugin for submitting posts from frontend. It's a field builder. Maybe it uses wp_insert_post() function, I really don't know. Here I use my custom shortcode, please check here for the code: ...
Juraj's user avatar
  • 11
1 vote
1 answer
104 views

Can this react script be optimized? How to make it faster

Rephrased the question on August 9th. This is my first attempt to work with Wordpress blocks and also my first time working with React. The code below adds the possibility to conditionally show blocks....
Tsjippy's user avatar
  • 11
0 votes
1 answer
454 views

Add action save post when create and publish

I try to use the hook save_post in my wp but I have a problem. I do this : function when_save_post_match($post_id, $post){ if (isset($post->post_status) && 'auto-draft' == $post->...
Gpi's user avatar
  • 111
0 votes
0 answers
67 views

Access NEW/UPDATED post values in save_post() callback function

I want to run a "background" function when a custom post type is saved (updated or created) using the NEW/UPDATED post values. The "background" function updates a taxonomy, based ...
dtw's user avatar
  • 105
2 votes
0 answers
95 views

Get $_POST & $_REQUEST values before adding/updating post

I've done this many times before, but it stopped working and I can't figure out why and haven't found a way to re-accomplish the same task. GOAL: intercept submitted values from $_POST/$_REQUEST ...
patrick34's user avatar
0 votes
1 answer
42 views

Update current WP post every 3 minutes [closed]

I wish to auto update/publish the changes of a post I am editing every 3 minutes. Any idea how can I achieve that?
Ryan Tan's user avatar
1 vote
1 answer
67 views

save_post_{CPT} not updating the 'sticky_posts' option

add_action( "save_post_{CPT}", 'update_sticky', 15, 1 ); function update_sticky( $post_id ) { $stickies = get_option( 'sticky_posts' ); if ( ! in_array( $post_id, $stickies ) ) { ...
Tahi Reu's user avatar
  • 298
0 votes
1 answer
125 views

How to check post meta isset or not empty during publish/save post?

How to check if a specific post meta isset/!emtpy during updating or publishing a post ( save_post() )?
Amenadiel's user avatar
  • 125
0 votes
0 answers
102 views

save_post trigerred twice

I am trying to add more functionality to the update button. My end result is that I wish to call a python script but for now I am messing around with writing a log file. This is resulting in the log ...
Martha's user avatar
  • 1
0 votes
0 answers
98 views

Updating failed. The response is not a valid JSON response. specific to my browser when I include javascript in my html

I was able to insert custom html into my gutenberg wordpress editor (hosted by bluehost) and test my code by preview with no problems. I made calls to google maps and fetch() to get a list of ...
Sugarplumclaus's user avatar
1 vote
0 answers
96 views

How can I remove the kses filters when saving a specific post type ? (it breaks my JSON)

I want to store JSON in my post_content, but the kses filters makes it break. I would like to remove the kses filters when creating or updating (well, saving) a specific post type; anywhere in the ...
gordie's user avatar
  • 492
1 vote
1 answer
53 views

Pre insert data when adding new custom post fire a json error

here is what i have tried function mec_locations_cpt_add_content ( $data, $postarr) { //, $postarr if ( 'mec_locations_cpt' !== $postarr['post_type'] ) { return $data; } if ...
ari elbaz's user avatar
1 vote
0 answers
27 views

Plugin with action 'save_post' needs to press publish twice on order to publish

I have an old plugin, which used to work fine (years ago). Now I have to press publish twice to publich the post. The problem is in the blocks below. The used variables are declared above the code ...
lassec's user avatar
  • 11
1 vote
0 answers
333 views

Strange issue saving custom field data for a WooCommerce order

I have an issue with WordPress update_post_meta() function. So I have made a custom input field for WooCommerce orders which hold Tracking number. Most of the time everything is running smooth and I ...
John McClane's user avatar
0 votes
1 answer
49 views

Custom Post Meta from custom metaboxes is randomly being deleted

For a while now I've been applying and updating some custom metaboxes that my company re-uses on different sites. (Not the same metaboxes, but the same methodology.) Essentially it allows for the '...
Tony Djukic's user avatar
  • 2,149
0 votes
0 answers
223 views

Save / Update meta data as multidimensional array

I need some help with saving my meta data from a post. On the editpage I have the following input fields <input type="text" name="data[color][]" value="red"/> <...
Liekeee's user avatar
0 votes
1 answer
197 views

Adding term to a custom taxonomy based on term from product category

spent over four hours on this and still hitting a wall, hope StackExchange knows better. :/ Basically, I have some Woo products and whenever a new product is added, its name should be saved as a term ...
Tatex's user avatar
  • 33
0 votes
1 answer
101 views

Exclude URL's from sanitize_html_classes

I've searched through the similar questions but found nothing. I've coded a meta box for adding custom URL's which get added to buttons on single posts but when the URL is added to the meta box field ...
Brad Dalton's user avatar
  • 6,936
0 votes
1 answer
301 views

How check if a post is saved from backend or frontend?

I created a custom post type called wasb_contact which can be inserted and edited both from the backend and from the frontend (through a form I created). The CPT has some custom meta fields which are ...
icolumbro's user avatar
3 votes
2 answers
2k views

Get updated post meta on save_post action?

I'm trying to save post id and keyword (Yoast Focus Keyword) to a custom table when post is created or updated via save_post action. It saves everything fine on Publish (first-time) but when I update ...
Key's user avatar
  • 135
0 votes
1 answer
156 views

Custom meta box values are not getting saved for my custom post type

I have created one dummy post type to check the values, if it's getting saved or not. However it's saving values for 'text input and text area' but remaining values (checkbox, select, images) are not ...
Ricky's user avatar
  • 53
1 vote
0 answers
417 views

"The link you followed has expired" & "Error while saving" messages when adding new post

I'm currently unable to publish new posts on my wordpress site. Whenever I try, I get a "The link you followed has expired" error after clicking the "publish" button. Also, as I'm ...
Harrison's user avatar
0 votes
1 answer
271 views

Wordpress sent multiple requests on update

I have a problem with hooks being fired multiple times when I press update on a post (page in this example) I tried everything here: Unable to prevent function using save_post firing twice But since ...
Borje's user avatar
  • 123
0 votes
0 answers
44 views

How to create a user ability to save pages with full url?

Problem: I have a real estate website with dynamic pages. For example when you click on a property it links to http://example.com/property/?id=23432434. I want to give users the ability to save a ...
Joey Lawrence's user avatar
3 votes
0 answers
2k views

Correct processing of `$_POST`, following WordPress Coding Standards

Background I'm building a project that according to the specifications need to follow the WordPress Coding Standards. I am using phpcs to scan my code. If I try to pass $_POST-data into a function ...
Fabian Mossberg's user avatar
0 votes
1 answer
285 views

Run function after a post has finished saving - callback function perhaps?

Upon saving a new post (of a certain post type), a given operation has to run. The problem is that the operation is calling an external (slow) API, which means that the (not logget in) end-user might ...
Zeth's user avatar
  • 888
0 votes
0 answers
204 views

Add Tag to post after publishing

I want to add a specific tag to posts being published, I tried the following code and searched for answers here but it doesn't work. Does anyone have an idea why? function tag_to_published_post( $...
fourorty's user avatar
1 vote
0 answers
218 views

Custom Taxonomy terms aren't getting referenced or saved in Quick Edit or Bulk Edit, only on Single product page?

I am using Woocommerce, Elementor, ACF Custom Fields and CPT for Custom Post types. I have a custom taxonomy called 'biographies' which has some associated custom fields (first name, last name, birth ...
Tim L's user avatar
  • 11
0 votes
2 answers
879 views

Wordpress publish_post hook not getting featured image and meta on first publish, but works on updating title

I've been struggling to find a solution for this and I don't know if it's the Gutenberg editor or if it's the hook publish_post. Hook: function api_method($post_id) { // If this is just a revision,...
msbodetti's user avatar
  • 103
0 votes
0 answers
569 views

Is there a way to get rendered html content of a WP post after updating?

I tried adding a filter at the content etc but that one just gives access to content stored in wp_posts. I am interested in getting the rendered html with meta tags etc for a post, after it is updated....
chatnoir's user avatar
0 votes
2 answers
48 views

When the new post which has no image published, save the specific image as the featured image ( by category )

As the title, I would like to save the post with the specific image as the featured image, when it is new published. Also I would like to save different images which is filtered by categories. I have ...
shinny0129's user avatar

1
2 3 4 5
8