Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在PODS分类法自定义表字段中搜索_Php_Mysql_Wordpress - Fatal编程技术网

Php 在PODS分类法自定义表字段中搜索

Php 在PODS分类法自定义表字段中搜索,php,mysql,wordpress,Php,Mysql,Wordpress,在PODS中,我创建了一个新的自定义分类法,并启用了额外的字段(因此它创建了一个新的数据库表:wp\u PODS\u taxname) 如何基于$search字符串在该表中搜索,并返回属于已找到分类法的所有帖子 我开始这样做,但却发现它工作不正常,可能在错误的位置搜索: $args = array( 'post_type' => 'book', 'tax_query' => array( 'relation' => 'OR', a

在PODS中,我创建了一个新的自定义分类法,并启用了额外的字段(因此它创建了一个新的数据库表:
wp\u PODS\u 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`

在我的例子中,“Customer”=带有自定义字段的分类法,“Review”=分配给分类法的post类型。我觉得这很接近。啊。

我已经弄明白了。显然,您需要使用点符号来表示密钥

解决方案:

    $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'
        )
    )

我已经弄明白了。显然,您需要使用点符号来表示密钥

解决方案:

    $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'
        )
    )