如果元键的值为 x 则 echo

发布于 2025-01-13 05:40:53 字数 870 浏览 0 评论 0原文

我有 3 段代码,本质上应该做同样的事情,但它们都不起作用,而且都在回响“不工作!”。

元键是 wilcity_belongs_to,值为 2980。这些都基于列表所在的计划。因此,如果列表计划的值为 2980,那么它必须回显“正在工作!”。

$meta = get_post_meta( get_the_ID(), 'wilcity_belongs_to',true );
if( $meta == '2980' ) {
    echo "Working!";
} else {
    echo "Not Working!";
};

并且

global $wpdb;
$wpdb->get_results( "select * from $wpdb->wpam_postmeta where meta_key = 'wilcity_belongs_to' " );
if ( $wilcity_belongs_to == '2980') {
    echo "Working!";
} else {
    echo "Not Working!";
};

if ( get_post_meta( $post->ID, 'wilcity_belongs_to', true ) == '2980' ) {
    echo "Working!";
} else {
    echo "Not Working!";
};

是数据库中内容的屏幕截图:数据库 这在表中:wpam_postmeta

请我在这方面获得帮助,我一直在尝试一切。

I have 3 pieces of code that essentially should do the same thing, but none of them are working and they are all echoing "Not Working!".

The meta key is wilcity_belongs_to and the value is 2980. These are all based on what plan a listing is on. So if the listing plan is value 2980 then it must echo "Working!".

$meta = get_post_meta( get_the_ID(), 'wilcity_belongs_to',true );
if( $meta == '2980' ) {
    echo "Working!";
} else {
    echo "Not Working!";
};

and

global $wpdb;
$wpdb->get_results( "select * from $wpdb->wpam_postmeta where meta_key = 'wilcity_belongs_to' " );
if ( $wilcity_belongs_to == '2980') {
    echo "Working!";
} else {
    echo "Not Working!";
};

and

if ( get_post_meta( $post->ID, 'wilcity_belongs_to', true ) == '2980' ) {
    echo "Working!";
} else {
    echo "Not Working!";
};

Here is a screenshot of what is in the database: Database
This is in Table: wpam_postmeta

Please could i get help on this, ive been trying everything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2025-01-20 05:40:53

你尝试过这种方法吗? get_results() 通常返回一个包含结果集的数组。

global $wpdb;
$result = $wpdb->get_results( "select * from $wpdb->wpam_postmeta where meta_key = 'wilcity_belongs_to' " );
foreach ($result as $row) {
   if ( $row["wilcity_belongs_to"] == '2980') {
       echo "Working!";
   } else {
       echo "Not Working!";
   };
};

Did you try this way? get_results() usually returns an array with the result set.

global $wpdb;
$result = $wpdb->get_results( "select * from $wpdb->wpam_postmeta where meta_key = 'wilcity_belongs_to' " );
foreach ($result as $row) {
   if ( $row["wilcity_belongs_to"] == '2980') {
       echo "Working!";
   } else {
       echo "Not Working!";
   };
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文