mercredi 4 novembre 2015

Search inside PODS Taxonomy custom table fields

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


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire