[wp-hackers] Plugin Help - Tag schema support in Search Everything

Daniel Cameron dan at scatter3d.com
Mon Oct 8 23:26:35 GMT 2007


I'm in desperate need for some fresh eyes to look at my code to see
what I'm doing wrong. It's most likely a simple fix but I could be
headed in a completely wrong direction. Hopefully you hackers can help
either way.

This portion is for category exclusion,


    //exclude categories/tags from search
    function SE4_exclude_categories($where) {
        global $wp_query;
        if (!empty($wp_query->query_vars['s'])) {
            $excl_list = implode(',', explode(',',
trim($this->options['SE4_exclude_categories_list'])));
            $where = str_replace('"', '\'', $where);
            $where = 'AND ('.substr($where, strpos($where, 'AND')+3).' )';
            //$where .= ' AND (c.category_id NOT IN ( '.$excl_list.' ))';
            $where .= "AND $wpdb->term_taxonomy.term_id NOT IN ($excl_list)";
        }

        $this->SE4_log("ex tags where: ".$where);
        return $where;
    }

    //join for excluding categories/tags
    function SE4_exclude_categories_join($join) {
        global $wp_query, $wpdb;

        if (!empty($wp_query->query_vars['s'])) {


            $where .= "LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN
$wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id =
$wpdb->term_taxonomy.term_taxonomy_id)";
        }
        $this->SE4_log("category join: ".$join);
        return $join;
    }


---------------------
Here is the code for including the tag name in the search that I can't
get to work as well,
---------------------

    //search tags
    function SE4_search_tags($where) {
        global $wp_query, $wpdb;
        if (!empty($wp_query->query_vars['s'])) {
            $where .= " OR terms_name LIKE '%" .
$wpdb->escape($wp_query->query_vars['s']) . "%' ";
        }

        $this->SE4_log("tags where: ".$where);

        return $where;
    }

    //join for searching tags
    function SE4_search_tags_join($join) {
        global $wp_query, $wpdb;

        if (!empty($wp_query->query_vars['s'])) {

            $join .= "LEFT JOIN $wpdb->term_relationships ON
($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
        }
        $this->SE4_log("tag join: ".$join);
        return $join;
    }



Tag search just doesn't work, no errors. The exclusion does produce an error.
 			

WordPress database error: [You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near 'NOT IN (1) ORDER BY post_date DESC LIMIT 0, 10' at
line 1]
 			 SELECT DISTINCT SQL_CALC_FOUND_ROWS 23_posts.* FROM 23_posts
WHERE 1=1 AND ( (((post_title LIKE '%test-asdf%') OR (post_content
LIKE '%test%'))) AND post_type = 'post' AND (post_status = 'publish'
OR post_status = 'private') )AND .term_id NOT IN (1) ORDER BY
post_date DESC LIMIT 0, 10


Here's the plugin repo and browser,
http://svn.scatter3d.com/search-everything/
http://searcheverything.scatter3d.com:3000/browser/trunk
However this code is not checked in (since it clearly doesn't work).


Thanks.





-- 
Dan Cameron


More information about the wp-hackers mailing list