Title: Adding a custom taxonomy to a SQL Query
Last modified: August 30, 2016

---

# Adding a custom taxonomy to a SQL Query

 *  [rrfranco92](https://wordpress.org/support/users/rrfranco92/)
 * (@rrfranco92)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-a-custom-taxonomy-to-a-sql-query/)
 * Hello Guys,
 * I’m trying to implement a new search option in store locator plugin.
 * I needed to add a custom taxonomy and I was successful with it but now I need
   it to work with the search system.
 * I have this SQL Query, which the plugin dev pointed me at, but I don’t know much
   about SQL so I’m asking for your help.
 *     ```
       $cat_filter = "INNER JOIN $wpdb->term_relationships AS term_rel ON posts.ID = term_rel.object_id
                                      INNER JOIN $wpdb->term_taxonomy AS term_tax ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id
                                             AND term_tax.taxonomy = 'wpsl_store_category'
                                             AND term_tax.term_id = %d";
       ```
   
 * Here I need to add the option of also search by my new custom taxonomy, which
   is called **wpsl_custom_category**.
 * I already tried adding by duplicating
    ** AND term_tax.taxonomy = ‘wpsl_custom_category’**
   but then neither of the search fields work.
 * Can you please help me with this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Jay](https://wordpress.org/support/users/phyrax/)
 * (@phyrax)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-a-custom-taxonomy-to-a-sql-query/#post-6574062)
 * There has to be a better way than searching with direct SQL? Also, this is a 
   fragment of a larger piece of code. Looks like it may be run through $wpdb->prepare
   or even a sprintf/printf call.
 * If you can either A. ) Provide the full file, or B. ) link to the plugin, there
   may be an easier way.
 *  Thread Starter [rrfranco92](https://wordpress.org/support/users/rrfranco92/)
 * (@rrfranco92)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/adding-a-custom-taxonomy-to-a-sql-query/#post-6574063)
 * The plugin is WP Store Locator
 * [https://wordpress.org/plugins/wp-store-locator/](https://wordpress.org/plugins/wp-store-locator/)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding a custom taxonomy to a SQL Query’ is closed to new replies.

## Tags

 * [custom](https://wordpress.org/support/topic-tag/custom/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)
 * [taxonomies](https://wordpress.org/support/topic-tag/taxonomies/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [rrfranco92](https://wordpress.org/support/users/rrfranco92/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/adding-a-custom-taxonomy-to-a-sql-query/#post-6574063)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
