php - 按自定义字段中的部分字符串查询
问题描述
我正在尝试查询是否存在于自定义字段中的字符串。
例如,在自定义字段中,我有一个值,例如:如果我有一个来自Milano romani
的字符串MilanoGET
,我应该找到它。但是即使自定义字段中没有字符串匹配,以下内容也会给我所有帖子
<?php
$myTerm = $_GET['cityName'];
$catIds = array();
$args = get_posts(
array(
'post_type' => 'post',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'usp-custom-23',
'value' => $myTerm,
'compare' => 'LIKE'
)
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$id = get_the_ID();
array_push($catIds, $id);
}
$catIds = implode( ", ", $catIds );
if(count($catIds) > 0){
$arrayFUllCity = "fullCity";
} else {
$arrayFUllCity = "empty";
}
}
var_dump($catIds);
?>
解决方案
推荐阅读
- python - 如何交换给定字符串中的字符?
- c# - 如何使用 json 正文发送 POST 请求?(RestSharp C#)
- pdf - 从 Google Apps Script HtmlOutput 打印到 pdf
- regex - 如何仅计算数字长度正则表达式
- php - 从另一个 PHP 文件调用类中的函数
- angular - 在解构项目和解构行为后创建一个新数组
- swift - 如何在使用 AVPlayer 时检测用户何时快速取消视频静音
- javascript - Javascript:查找父元素文本
- python - 蜘蛛迭代地找到一个html
- sql-server - SQL。查找时间间隔内的第一个和最后一个值,然后使用它们