doujingqu3030 2015-11-05 04:05
浏览 65
已采纳

在PODS Taxonomy自定义表字段中搜索

In PODS, I have created a new custom taxonomy with extra fields enabled (so it creates a new database table: wp_pods_taxname).

How can I search inside of this table based off of a $search string and return all posts that belong to found taxonomies?

I started to do this, but only to realize it doesn't work properly and that it may be searching in the wrong locations:

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

Any help would be appreciated!

Example taxonomy:

  • Authors, table storage attributes:
    • First Name
    • Last Name
    • Birthday

Example post type:

  • Books, can be assigned to a taxonomy (authors)

I want to be able to search all authors by first name, last name, or birthday - the search string being in $search. Then, I want to be able to display all books. So if $search = "Harper", I should see books:

  • To Kill a Mockingbird
  • Go Set a Watchman

Update,

So, I've been able to make some progress... but still returning 0 results. Updated query:

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

Yields: 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`

In my case, "Customer" = Taxonomy with custom fields, and "Review" = post type assigned to a taxonomy. I feel this is close. Agh.

  • 写回答

1条回答 默认 最新

  • douji1058 2015-11-05 05:11
    关注

    I have figured it out. Apparently you need to use dot notation for the key's.

    Solution:

        $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'
            )
        )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面