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.