私は以下を実行します:
注: 「UnitedStates」や「china」などのusp-custom-8
文字列を含むカスタムフィールドです
「[Image] United States」のように、国の先頭に余分な文字列がある場合があります。["Image"]を削除して、国名のみを残す必要があります。以下で私はがcustom field
特定のものstring
を持っているかどうかをチェックしようとしていました、もしそうなら、それを変更してくださいupdate the field
。しかし、それは機能していません。また、これは一発ですべての["Image"]を削除する一般的なコードではありませんが、国ごとに手動で実行する必要があります。
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;
[Image]
を使用してブランクに置き換えるという最も簡単なオプションを選択できますstr_replace()
...
if (have_posts()) :
while (have_posts()) :
the_post();
$title = usp_get_meta(false, 'usp-custom-8');
update_post_meta( $post->ID, 'usp-custom-8',
str_replace('[Image]', '', $title ));
endwhile;
endif;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加