【问题标题】:Wordpress update_option() not working consistently with variableWordpress update_option() 与变量不一致
【发布时间】:2019-11-20 07:39:21
【问题描述】:

我正在尝试将帖子元字符串同步到几个选项,它适用于第一个但不适用于第二个。

// Assume the value of 'mystring' is "FOOBAR"
$string = get_post_meta($postID,'mystring',true);

// Now set the first option to $string
update_option('first-option',$string,true);

// Now set the second option to $string
update_option('second-option',$string,true);

这会产生以下数据库值:

|   option_name  |   option_value  |
====================================
|   first-option |     FOOBAR      |
------------------------------------
|  second-option |                 |

如果我这样做:

// Assume the value of 'mystring' is "FOOBAR"
$string = get_post_meta($postID,'mystring',true);
$test = "TESTING";

// Now set the first option to $string
update_option('first-option',$string,true);

// Now set the second option to $test
update_option('second-option',$test,true);

我明白了:

|   option_name  |   option_value  |
====================================
|   first-option |     FOOBAR      |
------------------------------------
|  second-option |     TESTING     |

所以 a) 我可以更新这两个选项 b) 来自 post_meta 的 $string 正在被填充 c) $string 只能工作一次??

但这也不起作用:

// Assume the value of 'mystring' is "FOOBAR"
$string = get_post_meta($postID,'mystring',true);
$test = get_post_meta($postID,'mystring',true);

// Now set the first option to $string
update_option('first-option',$string,true);

// Now set the second option to $test
update_option('second-option',$test,true);

结果:

|   option_name  |   option_value  |
====================================
|   first-option |     FOOBAR      |
------------------------------------
|  second-option |                 |

因此,即使我从头开始将 $test 变量设置为与 $string 相同的值,第二个选项仍然为空白。

我显然在这里遗漏了一些东西。任何人都可以对此有所了解吗?

【问题讨论】:

  • 它会起作用的。检查您是否获得了 $test 的价值? $test = get_post_meta($postID,'mystring',true);
  • 好吧,我回去了,什么也没改变……现在它可以工作了。不知道为什么。无论如何,感谢您的意见。

标签: php wordpress options


【解决方案1】:

我回到这个项目,发现一切都按预期工作。不知道为什么不早点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多