Skip Navigation

[Resolved] wp_update_post inside cred_save_data not updating field guid

This thread is resolved. Here is a description of the problem and solution.

Problem:
wp_update_post not updating field guid in backend

Solution:
You should use the WordPress standard hook save_post to update the post information.

You can find the proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/wp_update_post-inside-cred_save_data-not-updating-field-guid/#post-1161346

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by rexJ-2 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1160844

I am trying to: simply update some fields but the guid field is not updating using cred_save_data function

$my_upost = array(
        	'ID'			=> $etid,
		   	'guid' 			=> '<em><u>hidden link</u></em>'.$etid,
		    'post_content'  => 'medarbejder er nu opdateret' .$post_id.' og post ID er: '.$etid
		   //'post_parent'	=> $post->ID
		   
		);
		wp_update_post($my_upost);

any idea why the guid field from within cred_save_data not get updated?
Link to a page where the issue can be seen:
password protected user
I expected to see: in mysql database the post table and guid field updated

Instead, I got: the guid field is not updated all other fields are

#1161346

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - could you please try to use the following code and try to resolve your issue:

function func_custom_update_post( $post_id, $post ){
    global $wpdb;
    
     if ( 'your-post-type-slug' == $post->post_type ) {
       $columns= array(
            'guid'          => '<em><u>hidden link</u></em>'.$etid,
            'post_content'  => 'medarbejder er nu opdateret' .$post_id.' og post ID er: '.$etid       
           );

        $wpdb->update( $wpdb->posts, $columns, array( 'ID' => $etid ) ); 
     }
}
add_action( 'save_post', 'func_custom_update_post', 30, 2 );

Where:
- Replace 'your-post-type-slug' with your post type slug

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/updating-types-fields-using-php/

#1161400

Solved by
1: Overall issue:
The general save_post action must be used with a priority of at least 30 when used in conjunction with post types registered with Types, or inconsistencies in the updated data may be experienced.
My issue is resolved now. Thank you!

2:

 $columns = array(
        	'ID'			=> $etid,
		   	'guid' 			=> '<em><u>hidden link</u></em>'.$etid,
		    'post_content'  => 'medarbejder er nu opdateret' .$post_id.' og post ID er: '.$etid
		   //'post_parent'	=> $post->ID
		   
		);
		$wpdb->update( $wpdb->posts, $columns, array( 'ID' => $etid ) );