2011-07-11 16 views
4

これは少し奇妙です、私は "update_post_meta"を使ってWordpressのカスタムフィールドを更新しています。私はupdate_post_meta($ post_id、 'Test_Field'、 'Test Value')を実行します。カスタムフィールドの更新問題のない私はそれが更新されない文字列値を使用する場合:あなたの助けをWordpress update_post_metaは動的値を更新しません

$test_value = "Test"; 
echo $test_value; // No problem here 
echo $post_id; // No problem here 
update_post_meta($post_id, 'Test_Field', $test_value); 

事前のおかげで非常に多くの

ステュー

+0

二重引用符で修正されていますが、誰でも知っていますか? update_post_meta( "$ page_id"、 "Test_Field"、 "$ test_value"); – Stuart

+0

どのように$ post_idを割り当てていますか?ちょうど推測 - すべてがうまく見えます、率直に。 – Bosworth99

答えて

3

型で変数をキャストしようとします。これを試してください:

update_post_meta((int) $post_id, 'Test_Field', (string) $test_value); 
1

あなたの最初の例で使用される$ post_idのをと解$ page_id。それはタイプミスですか?

+0

はいa typo。しかし、よく目撃された。 – Stuart

0

奇妙に聞こえるかもしれませんが、meta_keyの名前は入力フィールド名と同じでなければなりません。

update_post_meta($post_id, 'top_image', $_POST['top_image']);

関連する問題