Created
September 25, 2020 20:59
-
-
Save claytoncollie/37385f76f4957a95d22358e0d34a2ecb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'wp_insert_post_data', 'prefix_insert_post_data', 10, 3); | |
| /** | |
| * Filter the post data just before it goes to the database. | |
| * | |
| * Inserts custom fields into the post name and post title. | |
| * | |
| * @param array $data An array of slashed post data. | |
| * @param array $postarr An array of sanitized, but otherwise unmodified post data. | |
| * @return array | |
| */ | |
| function prefix_insert_post_data( array $data, array $postarr ) : array { | |
| // Return if not on proper post type. | |
| if ( ! in_array( $data['post_type'], array('post'), true ) ) { | |
| return $data; | |
| } | |
| $post_meta = get_post_meta( get_the_ID(), 'post_meta_key', true ); | |
| $data['post_title'] = wp_kses_post( $post_meta ); | |
| $data['post_name'] = sanitize_title_with_dashes( $post_meta ); | |
| return $data; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment