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
15 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 '...
0
votes
1answer
3k views

How to change the post author when the post is published?

I wanted to change the author when a post change from draft to publish. I have $_GET['auth_id'] variable in post edit screen like this ...wp-admin/post.php?post=53&action=edit&auth_id=5. I ...
1
vote
2answers
2k views

save_post custom post type ? $_POST not working?

i have this code. <?php add_action('add_meta_boxes', 'ct_meta_add'); add_action('save_post','ct_meta_save'); add_action('save_post','ct_parent'); // add meta functions function ct_meta_add() { ...
0
votes
0answers
17 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"/> <...
6
votes
2answers
5k 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 ...
0
votes
0answers
9 views

Select input in metabox not updated

I try to figure it out why my select input did not update the value. I have placed the select input in the header of a metabox, the same what Woocommerce did with the producttype selector. ...
0
votes
1answer
998 views

How to hook save-post function to use taxonomy term in post-slug?

Hook save-post function to check if taxonomy term is attached or not. If attached then, use taxonomy term in post slug like "taxonomy-term-other-words"...
0
votes
2answers
1k 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
4k views

Conditional for autosave or auto draft?

I am attempting to create a file using fopen() on save_post. I am having trouble finding the right condtionals to prevent the the file from being created from an auto save. I only want to create the ...
0
votes
1answer
649 views

Custom metabox does not store data

I'm troubled with a custom metabox, could someone give me a helping hand? I've got a custom post type which uses it, but unfortunately it's not storing the data into the database. Any clue? ...
0
votes
2answers
2k views

Save current post using custom save button

I want to display a custom button in my "Edit post" screen which saves the current post (everything including custom fields) and then runs a function (in my case redirecting to another page). I know ...
0
votes
1answer
2k views

Generate post title and permalink from custom field and post date

I have a custom post type with the following permalink structure /%match_season%/%match_team%/%postname%-%year%-%monthnum%-%day%/ %match_season% and %match_team% are taxonomies. The post type ...
0
votes
1answer
22 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 ...
0
votes
1answer
31 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 ...
0
votes
1answer
39 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 ...
1
vote
1answer
875 views

Saving zero as meta value

I have a meta_key called "_ordre" and each time I create a new custom post, a new meta_value is set for that meta_key. The thing is, when I set the value of '_ordre' to 0, the meta_value is not saved ...
3
votes
4answers
4k 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 ...
0
votes
1answer
770 views

post_title in save_post action

I use save_post action to save meta field and to check if post title is set. So I check the value returned by empty($post->post_title) but I get true also if I set the title.
0
votes
0answers
23 views

Bookmarking custom template pages which all have the same page ID

I have a custom page I created in WP which displays different real estate listings. Since it is a custom page the page ID is always the same. For example both of these URLs display different ...
2
votes
2answers
38 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 ...
0
votes
1answer
24 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 ...
0
votes
1answer
47 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 ...
1
vote
0answers
56 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 ...
0
votes
0answers
41 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 ...
0
votes
0answers
89 views

Save a custom field in a custom table when saving a draft

I created a custom metabox with a custom field inside. I attach code. add_action( 'admin_menu', 'mtb_add_metabox' ); function mtb_add_metabox() { add_meta_box( 'mtb_metabox', '...
23
votes
11answers
37k views

Check for update vs new post on save_post action

Is it possible within the save_post action to determine whether it's a new post being created or an existing post being update?
2
votes
0answers
434 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 ...
1
vote
2answers
410 views

Meta box html is not updating after saving

I have some meta boxes setup, some are my own, some are initialized in plugins. As the title indicates, these meta boxes are not updating graphically after the post has been submitted. Here's an ...
0
votes
0answers
21 views

Deleting CPT post by code (ie in a plugin) redirects to the main post type

Suppose a CPT In functions.php or in a plugin, hook on 'save_post' to perform some calculations upon hitting the Publish button in WP-Admin... Inside the hook's code include some conditional logic ...
0
votes
1answer
100 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 ...
0
votes
2answers
2k views

Remove image from post_content on save_post

I'm trying to setup a function in functions.php that removes an image from the post_content on save. Everything works up until the time I'm trying to save the content, the page just hangs and I get a '...
0
votes
0answers
28 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( $...
0
votes
2answers
2k 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 ...
0
votes
0answers
58 views

AJAX Saving a meta post does not work in Gutenberg using my save post button

I've created a meta box with posts and would like to save it by clicking the submit button. Saving with Ajax works well in the classic editor and stops working as soon as it moves to Gutenberg. Would ...
1
vote
3answers
9k views

Is there an easy way to AJAX-ify saving of post?

We have a plugin that allows us to manage custom post types and we'd like to add AJAX functionality in saving, editing, and deleting posts. I couldn't find similar problems in the internet so I'm ...
0
votes
0answers
61 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....
1
vote
0answers
55 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 ...
0
votes
2answers
163 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,...
4
votes
3answers
9k views

get post meta before it is updated (during SAVE_POST)

Lets say I have custom field on post editor, and I change value from AAA to ZZZ.. : add_action('save_post', function($post){ $value = get_post_meta($post->ID, 'mykey'); } , 1); How ...
0
votes
2answers
34 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 ...
0
votes
0answers
86 views

Post and Pages section inside WordPress admin are completely blank

Meta Tags - Undefined array due to meta tags! I have created my own custom post meta tags but all works fine until I test my WordPress theme on the new WordPress Installation. What I came through ...
0
votes
1answer
97 views

Change post author without using wp_update_post()

The standard or more obvious way to change a post author in WP is to use the wp_update_post() function, as shown in this question. But I am having an issue, described as follows: // Inside the ...
0
votes
1answer
23 views

How to detect that the save_post hook is calling the callback associated to the current edit post page only

I am using the save_post hook to handle updates in a post that are done via the admin edit post page. But since I have more than ten custom post types, the save_post associated to each one of them is ...
0
votes
1answer
192 views

Save values from a pre_post_update

I have looked around for an answer here but I didn't find exactly what I'm looking for so I give this a try: I'm creating a plugin. I've created a custom post type I've created a metabox associated ...
1
vote
0answers
38 views

Use the backbone.js client to save custom post type meta

So I have this small piece of code that renders an array of IDs: const selected = this.$data.list.selected; function get_ids(input, field) { const output = []; for (let i=0; i < input....
0
votes
1answer
318 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 ...
0
votes
0answers
42 views

Taxonomy Child Not Updating Unless I Click Update Twice

I am using code from this answer to create a new child taxonomy term, however for some reason the change only takes effect if I click update post twice. Clicking Update Post once doesn't save the ...
1
vote
0answers
14 views

How can I create a new user account while creating a new post, and then set that new user as the author of that new post?

I have a custom meta box with some user information fields, and when the post is published, the new user account is created, along with the new post. However, the new post's author is set as the ...
1
vote
2answers
883 views

Why does post-slug not get saved for drafts?

I am trying to get the value of the 'new-post-slug' (the bit that you can edit to customize your slug for a post, but bizarrely doesn't have a 'name' attribute as you'd expect a form field to have ... ...
0
votes
2answers
5k 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 ...

1
2 3 4 5
8