WordPress.org

Ready to get started?Download WordPress

Forums

How to replace,remove txt inside custom field? (2 posts)

  1. Mraztek
    Member
    Posted 2 years ago #

    example my custom field shows <?php echo get_post_meta($post->ID, name, true); ?>

    JuanCarlos

    i dont want to be editing post idiviualy i just want a code that can do this by itself almost like

    <?php echo str_replace

    istead of JuanCarlos i just want to show Juan and remove Carlos

    how can i do this

    i try this
    <?php echo str_replace('Carlos', get_post_meta($post->ID, name, true); ?>
    but is not working!

    thanks

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    http://php.net/manual/en/function.str-replace.php
    try it with this:

    $name = get_post_meta($post->ID, 'name', true);
    if($name != '') {
    echo str_replace('Carlos', '', $name);
    }

Topic Closed

This topic has been closed to new replies.

About this Topic