Intranet breaking with Custom SQL code
-
I have written a custom sql statement that will act as the filter for my posts, pages and documents. Unfortunately when i am trying to transform my sqlquery to work in WordPress it is breaking our site and there is no way for me to debug it.
Could anyone suggest the best way to imbed this SQL statement into my functions.php page in order for it to work? Thanks!
function wpb_search_filter($query) { global $current_user; global $current_user_Location; $current_user = wp_get_current_user(); $current_user_Location=get_metadata( 'user', $current_user->ID, 'mo_ldap_local_custom_attribute_l', true ); global $wdpb; global $sqlquery; global $strSite1; global $strSite2; global $strSite3; $sqlquery = "SELECT DISTINCT wp_posts.id FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id AND wp_terms.name IN ('{$strSite1}', '{$strSite2}', '{$strSite3}') UNION ALL SELECT DISTINCT posts.id FROM wp_posts posts WHERE NOT EXISTS( SELECT * FROM wp_posts, wp_term_relationships, wp_term_taxonomy, wp_terms WHERE posts.id = wp_posts.id AND wp_posts.id = wp_term_relationships.object_id AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy IN ('post_tag','wpfd-tag') AND wp_term_taxonomy.term_id = wp_terms.term_id) AND posts.post_type IN ('wpfd_file', 'page', 'post') AND posts.post_status NOT IN ('auto-draft', 'trash')"; if ($query->is_search) { if ($current_user_Location == 'CR'){ $strSite1 = "'Craigavon'"; $strSite2 = "'All'"; $strSite3 = "'UK'"; } $query = $wpdb->get_results($sqlquery); return $query; } add_filter('pre_get_posts','wpb_search_filter');
Or can anyone see where I am going wrong?
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Intranet breaking with Custom SQL code’ is closed to new replies.