最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

save post - update a custom field with the value of another existing custom field

programmeradmin2浏览0评论

I am trying to write a function to copy the value of an imported custom field (postalCode) to another custom field (wpcf-adres) when the post is saved or created. But i cannot get it to work, so there must be something not right in the code? Thanks for any advice or solution given!

function sync_postalcode( $post_id ) {
 // GET Postal code FROM OTHER FIELD
     $postcode = get_post_meta( $post_id, 'postalCode', true);
 // UPDATE Postalcode IN adres FIELD
 update_post_meta( $post_id, 'wpcf-adres', $postcode );
 }

add_action( 'save_post', 'sync_postalcode' );
发布评论

评论列表(0)

  1. 暂无评论