Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
40 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
61 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
31 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($...
-1
votes
0answers
26 views

Automatically populate custom taxonomy with a value from a custom field

I'm working on a real estate website, and right now we have a feed importing new regional listings automatically (RETS feed). Certain fields in the 'properties' post type that comes with the real ...
0
votes
0answers
14 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
70 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
0answers
28 views

save_post hook doesn't get called when cpt supports 'editor'

I am building a custom post type. I want to use the save_post hook to validate inputs and flag a message to the admin screen when something is incorrect and save the post as a draft until those ...
0
votes
1answer
18 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
24 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
22 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
1answer
194 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
176 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
22 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
22 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
24 views

save_post, post_status isnt the excatly what in the database

add_action("save_post", [$this, "save"]); function save($postId) { $post = get_post($post_id); echo $post->post_status; // its "inherit" instead of "publish" ! echo $post->...
1
vote
1answer
37 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
89 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
152 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
2answers
163 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
85 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
45 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
46 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
0answers
21 views

Store tokens from Limesurvey to WordPress Posts or PostsMeta

After reading pages over pages about what best practice is to store data I'm more unsure than before. The Use Case: Register or Login to WP Click on "new feedback" URL leads to LimeSurvey where a ...
0
votes
2answers
66 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
17 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
47 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
64 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( '...
0
votes
0answers
30 views

Function executing twice on post first publish hook

I am hooking into save_post when a post is published for the first time. The function will send off to an API to shorten the URL. Everything works good, but the problem is that it's generating 2 links ...
3
votes
3answers
277 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
111 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
61 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
52 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
269 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
868 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
75 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
33 views

When deleting post, save_post hook error

I have a error in my code. I have custom-post-type(book). and, in this custom-post-type there are some metaboxes to be added. The code is like below. function rnm_save_book_post( $post_id, $post, $...
0
votes
0answers
48 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', '...
-1
votes
1answer
58 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?
0
votes
0answers
28 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
68 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
12 views

create and assign image to specific post ACF

I want to create a media image by having an url of an external image. For example, I have that $imgurl = "https://i.ytimg.com/vi/BPNTC7uZYrI/sddefault.jpg"; $postid = 145; Knowing that I have a ...
0
votes
0answers
90 views

Hook after post was created to update Custom Fields

I'm tryin to update post meta after a post was created but the get_post_meta function is not working. I have tried transitions, and almost every hook from documentation. The save_post_post , ...
0
votes
1answer
256 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 ...
0
votes
1answer
57 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 ...
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 ...
1
vote
4answers
480 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 ...
0
votes
1answer
98 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 ...
0
votes
1answer
16 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
50 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 ...
1
vote
1answer
583 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 ...