Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. <?php
  2.  
  3. add_action('init', 'jmd_phone_field_format');
  4.  
  5. function jmd_phone_field_format(){
  6.  
  7. $args = array(
  8. 'post_type' => 'job_listing',
  9. 'post_status' => 'publish',
  10. 'posts_per_page' => -1
  11. );
  12. $posts = get_posts($args);
  13. foreach ( $posts as $post ) {
  14.  
  15. $string = get_post_meta($post->ID, '_job_phone', true);
  16. preg_match_all('/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/i', $string, $matches);
  17. if ( ! empty ($matches[1]) ) {
  18. $output = '(' . $matches[1][0] . ')' ." ". $matches[2][0] .'-' . $matches[3][0];
  19. update_post_meta( $post->ID, '_job_phone', $output );
  20. }
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement