Stack Exchange Network

Stack Exchange network consists of 175 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
26 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
23 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
31 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
40 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
32 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
32 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
23 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
46 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
115 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
45 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
32 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
107 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
21 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
29 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
29 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
2answers
350 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
216 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
24 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
29 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
26 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
41 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
125 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
199 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
275 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
105 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
52 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
56 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
23 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
93 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
19 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
63 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
79 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( '...
3
votes
3answers
346 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
130 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
69 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
63 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
373 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
1k 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
88 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
54 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
105 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
29 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
71 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
109 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
286 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
75 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
656 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
110 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
17 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 ...