在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
="哈珀",我应该看书:
更新
所以,我已经取得了一些进展......但仍然返回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);
收率: SELECT
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`
就我而言,"客户" =具有自定义字段的分类法,以及"评论" =分配给分类的邮政类型。我觉得这很接近。 AGH。
答案 0 :(得分:0)
我已经弄清楚了。显然你需要使用点符号来表示密钥。
解决方案:
$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'
)
)