I run the following:
Note: usp-custom-8
is a custom field with a string like "United States" or "china" etc
Sometimes the nations have an extra string at the beginning like: "[Image] United States" and I need to remove ["Image"] and leave the country name only. With the following I was trying to check if the custom field
has a particular string
and if so, change it and update the field
. But it isn't working and also, this won't be a general code which in one shot will remove all ["Image"] but I'd have to manually run it for each country.
if (have_posts()) : while (have_posts()) : the_post();
$title = usp_get_meta(false, 'usp-custom-8');
if (preg_match('/\b[Image] United States\b/', $title)) {
update_post_meta( $post->ID, 'usp-custom-8', 'United States' );
}
endwhile; endif;