Title: [BUG FOUND   SOLUTION] &#8211; Problem when using custom prefix
Last modified: August 22, 2016

---

# [BUG FOUND SOLUTION] – Problem when using custom prefix

 *  [doxadigital](https://wordpress.org/support/users/doxadigital/)
 * (@doxadigital)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/bug-found-solution-problem-when-using-custom-prefix/)
 * i’m using it with wordpress v3.9 and found problem when using custom prefix table(
   not using “wp_” prefix)
 * The problem lies in category filter it using plain wp_ query:
 *     ```
       $rows = $wpdb->get_results("SELECT wp_terms.name, wp_term_taxonomy.term_taxonomy_id
       									FROM wp_terms, wp_term_taxonomy
       									WHERE wp_terms.term_id=wp_term_taxonomy.term_id
       									AND wp_term_taxonomy.taxonomy='category' ");
       ```
   
 * Solution:
    Around line 114, change:
 *     ```
       $table_name = $wpdb->prefix . "terms";
   
       		$rows = $wpdb->get_results("SELECT wp_terms.name, wp_term_taxonomy.term_taxonomy_id
       									FROM wp_terms, wp_term_taxonomy
       									WHERE wp_terms.term_id=wp_term_taxonomy.term_id
       									AND wp_term_taxonomy.taxonomy='category' ");
       ```
   
 * TO
 *     ```
       $table_name = $wpdb->prefix . "terms";
       		$table_name_taxonomy = $wpdb->prefix . "term";
   
       		$rows = $wpdb->get_results("SELECT ".$table_name.".name, ".$table_name_taxonomy."_taxonomy.term_taxonomy_id
       									FROM ".$table_name.", ".$table_name_taxonomy."_taxonomy
       									WHERE ".$table_name.".term_id=".$table_name_taxonomy."_taxonomy.term_id
       									AND ".$table_name_taxonomy."_taxonomy.taxonomy='category'");
       ```
   
 * Around line 138:
    CHANGE:
 *     ```
       $rows_id = $wpdb->get_results("SELECT term_taxonomy_id
       										   FROM wp_term_relationships
       										   ");
       ```
   
 * TO
 *     ```
       $rows_id = $wpdb->get_results("SELECT term_taxonomy_id
       										   FROM ".$table_name_taxonomy."_relationships
       										   ");
       ```
   
 * Hope this helps
 * [https://wordpress.org/plugins/popularity-posts-widget/](https://wordpress.org/plugins/popularity-posts-widget/)

The topic ‘[BUG FOUND SOLUTION] – Problem when using custom prefix’ is closed to
new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/popularity-posts-widget_ffffff.svg)
 * [Popularity Posts Widget](https://wordpress.org/plugins/popularity-posts-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/popularity-posts-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/popularity-posts-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/popularity-posts-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/popularity-posts-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/popularity-posts-widget/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [doxadigital](https://wordpress.org/support/users/doxadigital/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/bug-found-solution-problem-when-using-custom-prefix/)
 * Status: not resolved