WordPress.org

Ready to get started?Download WordPress

Forums

Simple Text Replace
How replace string in Custom fields? (4 posts)

  1. 3x7
    Member
    Posted 1 year ago #

    Is there any way to replace the string in a custom field?

    Thanks!

    http://wordpress.org/extend/plugins/simple-text-replace/

  2. dben
    Member
    Plugin Author

    Posted 4 months ago #

    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

  3. 3x7
    Member
    Posted 4 months ago #

    will try it out... can u please give me an example?

    Thanks!

  4. dben
    Member
    Plugin Author

    Posted 4 months ago #

    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);

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.