php - Wordpress:php strpos 不适用于 WP_Query
问题描述
好的,所以基本上我有这个代码:
<?php $query = new WP_Query( array( 'meta_key' => 'usp-custom-1', 'meta_value' =>
get_permalink() ) );
echo $query->found_posts;
if (strpos($query, "0") !== false) {
echo "yes";
} else {
echo "no";
}
?>
我想要实现的是,当 WP_Query 输出(找到的帖子)为 0 时,它会说是,否则不会。
但它不起作用。
不管数字多少,它总是说是。
我想我在这里遗漏了一些东西。
不是码农,
迫切需要帮助。
解决方案
只需与$query->found_posts
而不是使用比较strpos
。
<?php
$query = new WP_Query(
array(
'meta_key' => 'usp-custom-1',
'meta_value' => get_permalink()
)
);
echo $query->found_posts;
if (0 === $query->found_posts ) {
echo "yes";
} else {
echo "no";
}
?>
推荐阅读
- git - 尝试将代码推送到 GitHub Online 上的特定分支
- excel - 表问题中的动态超链接
- python - 带有mysql的Tensorflow Python 3 Docker Image无法安装
- sql - 通过分组计算列中唯一值的出现次数并在结果中引入其他列而不分组
- typescript - 如何告诉 TypeScript 接口 T 比具有索引签名的类型 U 窄?
- sql - SQL - 选择每个平台上至少有一个副本的主 ID
- python - 将自定义 CLI 命令映射到 Python 脚本
- swift - 使用 MVVM 模式处理 SwiftUI 和 CoreLocation
- react-admin - 如何在 react admin v3.1 上捕获用户登录成功?
- android - 方向改变时Android工具栏弹出菜单WindowLeaked