Title: How replace string in Custom fields?
Last modified: August 21, 2016

---

# How replace string in Custom fields?

 *  [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/how-replace-string-in-custom-fields/)
 * Is there any way to replace the string in a custom field?
 * Thanks!
 * [http://wordpress.org/extend/plugins/simple-text-replace/](http://wordpress.org/extend/plugins/simple-text-replace/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [dben](https://wordpress.org/support/users/dben/)
 * (@dben)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-replace-string-in-custom-fields/#post-3855958)
 * You need to add text replace code in simple-text-replace_hooks.php.
 * As you can see, by now only post content is replaced:
 * `$post['post_content'] = apply_regex_option($post['post_content'], 'content','
   01');`
 * Let me know if you need more help
 * daniele
 *  Thread Starter [3×7](https://wordpress.org/support/users/3x7/)
 * (@3x7)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-replace-string-in-custom-fields/#post-3855959)
 * will try it out… can u please give me an example?
 * Thanks!
 *  Plugin Author [dben](https://wordpress.org/support/users/dben/)
 * (@dben)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/how-replace-string-in-custom-fields/#post-3855960)
 * You should do something like this:
 *     ```
       // read custom field
       $customFieldValue = get_post_meta( $post_id, $key );
   
       // apply regular expression
       // you can set 'content' or 'title' in type argument to select which
       // expressions to apply (see options in WP admin)
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '01');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '02');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '03');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '04');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '05');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '06');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '07');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '08');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '09');
       $customFieldValue = apply_regex_option($customFieldValue, 'content', '10');
   
       // save custom field
       add_post_meta($post_id, $meta_key, $meta_value);
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How replace string in Custom fields?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/simple-text-replace.svg)
 * [Simple Text Replace](https://wordpress.org/plugins/simple-text-replace/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-text-replace/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-text-replace/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-text-replace/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-text-replace/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-text-replace/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [dben](https://wordpress.org/support/users/dben/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/how-replace-string-in-custom-fields/#post-3855960)
 * Status: not resolved