Skip to content

Instantly share code, notes, and snippets.

@johnbocook
Created September 28, 2013 05:28
Show Gist options
  • Save johnbocook/6738693 to your computer and use it in GitHub Desktop.
Save johnbocook/6738693 to your computer and use it in GitHub Desktop.
Find and replace custom field data in wordpress.
<?php
find_replace_custom_field_data( $post_ID = NULL, $custom_field_name = NULL, $search_for = NULL, $replace_with = NULL ) {
if ( isset( $post_ID ) && isset( $custom_field_name ) )
$get_ custom_field = get_post_meta( $post_ID, $custom_field_name, TRUE );
$custom_field_new = str_replace( $search_for, $replace_with, custom_field );
set_post_meta( $post_ID, $custom_field_new );`
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment