Put the below code in the theme’s functions.php file.
1 2 3 4 5 6 7 8 | add_filter( 'wp_insert_post_data', 'wpse_121035', 50, 2 ); function wpse_121035( $data, $postarr ) { //Check for the post statuses you want to avoid if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { $data['post_name'] = sanitize_title( $data['post_title'] ); } return $data; } |
自动将自定义字段的值填充到title和permalink,注意检查如果对title进行了是否为空的判断,需要设置两个钩子动作的优先级
原文链接:https://xiaohost.com/10737.html,转载请注明出处。
评论0