【发布时间】:2016-02-05 19:29:38
【问题描述】:
在 PODS 中,我创建了一个启用了额外字段的新自定义分类法(因此它创建了一个新的数据库表:wp_pods_taxname)。
如何根据 $search 字符串在此表中搜索并返回属于找到的分类法的所有帖子?
我开始这样做,但只是意识到它不能正常工作并且它可能在错误的位置进行搜索:
$args = array(
'post_type' => 'book',
'tax_query' => array(
'relation' => 'OR',
array(
'taxonomy' => 'author',
'field' => 'first_name',
'terms' => $search,
'operator' => 'LIKE'
),
array(
'taxonomy' => 'author',
'field' => 'last_name',
'terms' => $search,
'operator' => 'LIKE'
),
)
);
$query = new WP_Query($args);
任何帮助将不胜感激!
分类示例:
- 作者、表存储属性:
- 名字
- 姓氏
- 生日
示例帖子类型:
- 书籍,可以分配给分类(作者)
我希望能够按名字、姓氏或生日搜索所有作者 - 搜索字符串位于 $search 中。然后,我希望能够显示所有书籍。所以如果$search = "Harper",我应该看书:
- 杀死一只知更鸟
- 去设置守望者
更新,
所以,我已经取得了一些进展……但仍然返回 0 个结果。更新查询:
$pods = pods('review');
$search = $wpdb->esc_like($search);
$params = array(
'where' => array(
'relation' => 'OR',
array(
'value' => $search,
'key' => 'customer.d.first_name',
'compare' => 'LIKE'
),
array(
'key' => 'customer.d.last_name',
'value' => $search,
'compare' => 'LIKE'
)
)
);
$res = $pods->find($params);
var_dump($res);
产量: 选择
DISTINCT
`t`.*
FROM `wpcc_posts` AS `t`
LEFT JOIN `wpcc_term_relationships` AS `rel_customer` ON
`rel_customer`.`object_id` = `t`.`ID`
LEFT JOIN `wpcc_term_taxonomy` AS `rel_tt_customer` ON
`rel_tt_customer`.`taxonomy` = 'customer'
AND `rel_tt_customer`.`term_taxonomy_id` = `rel_customer`.`term_taxonomy_id`
LEFT JOIN `wpcc_terms` AS `customer` ON
`customer`.`term_id` = `rel_tt_customer`.`term_id`
LEFT JOIN `wpcc_pods_customer` AS `customer_d` ON
`customer_d`.`id` = `customer`.`term_id`
WHERE ( ( ( ( `customer_d`.`first_name` LIKE "%Jon%" ) OR ( `customer_d`.`last_name` LIKE "%Jon%" ) ) ) AND ( `t`.`post_type` = "review" ) AND ( `t`.`post_status` IN ( "publish" ) ) ) AND ( `t`.`post_title` LIKE '%Jon^%' )
ORDER BY `t`.`menu_order`, `t`.`post_title`, `t`.`post_date`
LIMIT 0, 15`
在我的例子中,“客户”= 具有自定义字段的分类,而“评论”= 分配给分类的帖子类型。我觉得这很接近。啊。
【问题讨论】: