Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('init', 'jmd_phone_field_format');
- function jmd_phone_field_format(){
- $args = array(
- 'post_type' => 'job_listing',
- 'post_status' => 'publish',
- 'posts_per_page' => -1
- );
- $posts = get_posts($args);
- foreach ( $posts as $post ) {
- $string = get_post_meta($post->ID, '_job_phone', true);
- preg_match_all('/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/i', $string, $matches);
- if ( ! empty ($matches[1]) ) {
- $output = '(' . $matches[1][0] . ')' ." ". $matches[2][0] .'-' . $matches[3][0];
- update_post_meta( $post->ID, '_job_phone', $output );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement