Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Reply To: Types – run own function in custom fields

$
0
0

Hello,
I need to re-write my title:

I would like to, when saving or updating a post-type run a function in the functions.php file.
I do succed with running the function, but I do have a problem when I would like to save a post meta value.
The post-meta value is important since I would like to change it later on for my purpose, but for the moment I just want to save a text in the meta value.

When saving the post, then the post meta value is not changed, so I saved the post again, and directly after that I checked at the database, then I could see the new value post meta value which was:
'new post meta value'

but when the post was fully loaded after saving the post, it got the old value from the database.
What am I doing wrong?

Please help me, perhaps someone could try this and help me.

Thanks for all kind of assistance.

here is the code,

function save_metadata($post_id) {
	global $post;
    // check autosave  
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)  
        return $post_id;  
    // check permissions  
    if ('page' == $_POST['post_type']) {  
        if (!current_user_can('edit_page', $post_id))  
            return $post_id;  
        } elseif (!current_user_can('edit_post', $post_id)) {  
            return $post_id;  
    } 
	$new = 'new post meta value';
	update_post_meta($post_id, 'wpcf-extra-description', esc_attr($new)) ;
}
add_action( 'save_post', 'save_metadata');

Viewing all articles
Browse latest Browse all 20145

Trending Articles