How can I trigger a javascript function after a post update on edit post screen in wordpress admin panel?

I use Wordpress 5.2.2 and I develop a custom theme. EDIT : On my theme I added a metabox who show an input type="text". Code in functions.php of my theme if ( ! function_exists( 'vn_add_metabox' ) ) { function vn_add_metabox () { add_meta_box('vn_youtube_single_metabox', __('Youtube link', WP_THEME_TEXTDOMAIN), 'show_vn_youtube_link_metabox', array('post', 'page'), 'side', 'low'); } add_action( 'add_meta_boxes', 'vn_add_metabox' ); } This metabox call show_vn_youtube_link_metabox who display an input text and youtube video iframe if (!function_exists('show_vn_youtube_link_metabox')) { function show_vn_youtube_link_metabox() { global $post; show_vn_input_text('vn_youtube_link'); // …
Category: Web

Set a post expiration and delete a post when expirate

I'm trying to create a function that allows me to delete an article when the date of the day is equal or superior than a date filled in a custom ACF field. I wrote the function below that I placed in my single.php in order to test it. It works, except that you must be reading the article in question for this function to execute (pretty logical actually). What I want is that this function runs itself on all the …
Category: Web

Post/Page Publish/Update button not clickable once I make an edit

I open a page and make an edit and the update button becomes grayed out. I have to copy all page content, refresh the page and paste it back in the page, only then does the update button become clickable. It does update the page so there is no issue with that. Only when making the initial edit is in not clickable. Update: I was able to recreate the issue, but not faithfully. It seems to occur when the page …
Category: Web

How trigger to save post when updating post meta

I have very confused situation. I have added posts and all posts metas from one website db to another one, everything is fine, images, title, description of posts are there. But post metas are not showing on webpage(img1), although they are exists when I go to post edit page in wp-admin(img2), I can see the post data , but they are not showing until I click to 'Update' button myself. After that all post data is showing.(img3,img4) Posts are to …
Category: Web

Autopopulate a value

I created an options page where users can enter their Google Captcha key and secret. Using update_option I am able to add these values to Elementor's settings. I'm trying to do the same with JetForm but it seems to need these values actually added to the settings page. If I overwrite them with update_option the captcha option doesn't even appear on the form source code. Is there a way to have my option's page settings actually appear in the fields …
Category: Web

remove_action('save_post') in function that was triggered by save post not working

The goal Update post title and slug on successful insertion into post table without re-triggering the save_post hook. Current behavior The function as it is, still triggers the save_post hook, even though I'm removing the action before wp_update_posts is invoked. When this code exists by itself, the code runs perfectly, however I have another piece of code that is triggered by the save_post hook, but only continues when the post is updated. When that function exists, the save_post hook that …
Category: Web

Update button (sometimes) greyed-out

I'd say about 50% of the time when I edit a post the 'update' is greyed out. What I do is copy the mark-up, refresh then re-apply and publish which is a bad work-around because it doesn't address the problem. Any ideas? I guess I can disable plugins but because the error comes and goes it might take a long time to identify a rogue plugin.... I guess my question is - what would cause this behavior? Thanks - and …
Category: Web

$wpdb->update() always need a second try

I will use a custom endpoint of REST APi to update fields in a custom table. Therefore, i wrote this function: function update_table_single($request = null){ global $wpdb; $data_key = trim($request['data_key']); $data_value = trim($request['data_value']); $where_key = trim($request['where_key']); $where_value = trim($request['where_value']); $table = trim($request['table']); $data = [ $data_key => $data_value ]; $where = [ $where_key => $where_value ]; $wpdbupdate = $wpdb->update($wpdb->prefix.$table, $data, $where); // $wpdbupdate = $wpdb->query( // $wpdb->prepare( "UPDATE $wpdb->prefix.$table SET $data_key = %s WHERE $where_key = %d", $data_value, $where_value ) …
Category: Web

wp_update_post deletes post meta in CPT

I have a custom post type called 'directory' and it includes a few meta/custom fields. The script below is meant to just change the post status only when run. This isn't on the admin panel where you save the post. This is a stand alone script run by itself. require('../../../wp-blog-header.php'); global $wpdb; global $post; $directories = get_posts( $get_directories ); foreach ($directories as $directory){ wp_update_post(array('ID' => $directory->ID,'post_status' => 'draft')); }; The status is updated fine, but the custom meta data is …
Category: Web

Prevent other hooks from firing after wp_update_post() outside of editor

I'm working on a plugin that batch updates post content using a call to wp_update_post(). This all happens outside the editor window, in a batch processing script. My problem is that ACF is firing after I run the wp_update_post() call as I think its because of the save_post hooks that run. This is blanking all my ACF meta, as the values are not present in the post array at that point in time, so how can I prevent anything else …
Category: Web

Set post publish date by custom field

I created custom fields with ACF to define a new date for my post on wordpress. I then created this function that updates the date with my custom field and works when I update a post. // Save ACF custom field to date-time post function my_acf_save_post( $post_id ) { $acfDate = get_field('data_time_post', $post_id); //Test if you receive the data field correctly: //echo $acfDate; //exit (-1); $my_post = array(); $my_post['ID'] = $post_id; $my_post['post_date'] = $acfDate; wp_update_post ( $my_post ); } add_action('acf/save_post', …
Category: Web

Why wp_update_post() does not update GUID?

Trying to update GUID on a attachment using the wp_update_post() function but its not updating GUID nor its throwing any error. Example code: $post = [ 'ID' => 45, 'guid' => 'https://example.com/foo.png' ]; wp_update_post($post);
Category: Web

SQL / wp_update_post: change post custom field to CPT post taxonomy

the setup is as follow: I have posts with a custom field: actor = 'tom hanks' for advanced management I created a custom post type (actors) and added "tom hanks" as a post within that actors taxonomy. Via plugin 'Advanced custom fields' I connected the custom taxonomy (actors) to the default posts so I can select 'tom hanks' on the regular post page. This can be done manually (check the custom field value and click the according actors category) but …
Category: Web

Why does wp_update_post causes white screen?

I made a custom post type, named "Foglalás". Each post in the Foglalás post type has neither title nor permalink. All of them are kind of Auto Draft after saving. So, I would like to get the post ID and set it to be the title and permalink as well. I use the following code: function foglalasi_adatok( $post_id ) { $post = array( 'ID' => $post_id, 'post_title' => $post_id, 'post_name' => $post_id, ); wp_update_post( $post ); update_post_meta($post_id, 'foglalas_szama', $post_id); } …
Category: Web

Updating post_parent by id (many times)

How can I update post_parent by ids? I tried: add_action('init','updating_parent'); function updating_parent(){ $args = array( 'post__in' => array(208,51) ); $my_posts = get_posts( $args ); foreach ( $my_posts as $my_post ): $my_post['post_parent'] = 12; wp_update_post( $my_post ); endforeach; } But this is not working. But even it wouldn't be what I need. Since I have data like: ID => post_parent 208 => 12 51 => 19 and so on... So I need an array at post_parent as well.
Category: Web

Update post meta is slow while saving post

Post saving took much time. I have action to save custom metas using update_post_meta add_action( 'save_post_property', 'propertys_save' ); function propertys_save($id) { foreach($_POST['meta'] as $k => $v) { $time_start = microtime(true); update_post_meta($id,$k,$v); echo microtime(true) - $time_start } } and i get this average timing: 0.16451787948608 And if i call update_post_meta anywhere in another place (for example admin-ajax.php?action=123) it will take: 0.00014281272888184s It's 1000 times faster... Is there any way to speed it up?
Category: Web

update post status with cron

Hi I am trying to update the status of a woocommerce order this is what I have at the moment I know the field content matches and if I write this as DB query and run it in phpmyadmin it works can anyone see what is missing for this to work. It is simply matching the date from the custom field to today I have double checked the format it's correct I've tested the output of the $today=date('j F, Y"); …
Category: Web

Is it possible to "Update" pages via SQL?

How can I "update" a page in WordPress using MySQL? I.e., effectively click the "update" button in the page editor using MySQL? But not make any changes to the page? What I'm doing: I'm making some bulk changes in wp_postmeta using a MySQL query in PHPMyAdmin, i.e. Woocommerce product data. I've discovered that each page needs to be manually "Updated" in the page editor for the product data to appear correctly on the front end. Once I make the changes …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.