2016-08-08 12 views
0

Ich habe Suchfeld auf der Seite, die Standard-WP-Feld ist denke ich. Wenn ich den Suchknopf drücke, sucht er richtig in der Tabelle posts und zeigt alle Ergebnisse an.Beitreten zweite Tabelle in Abfrage gibt nichts zurück in WordPress

Jetzt möchte ich zweite Tabelle von wo auch suchen und Ergebnisse von dort zeigen, wenn es welche gibt.

So in der function.php Datei im Theme-Ordner Ich habe das hinzugefügt:

function vh_search_meta_data_join($join) { 
    global $wpdb; 

    // Only join the post meta table if we are performing a search 
    if (get_query_var('s') == '') { 
     return $join; 
    } 

    // Only join the post meta table if we are on the Contacts Custom Post Type 
    if (!in_array('videogallery', get_query_var('post_type'))) { 
     return $join; 
    } 

    // Join the post meta table 
    $join .= " LEFT JOIN ".$wpdb->prefix."hdflvvideoshare"; 

    return $join; 
} 

function vh_search_meta_data_where($where) { 
    global $wpdb; 

    // Only join the post meta table if we are performing a search 
    if (get_query_var('s') == '') { 
     return $where; 
    } 

    // Only join the post meta table if we are on the Contacts Custom Post Type 
    if (!in_array('videogallery', get_query_var('post_type'))) { 
     return $where; 
    } 

    // Get the start of the query, which is ' AND ((', and the rest of the query 
    $startOfQuery = substr($where, 0, 7); 
    $restOfQuery = substr($where ,7); 

    // Inject our WHERE clause in between the start of the query and the rest of the query 
    $where = $startOfQuery . "(" . $wpdb->prefix."hdflvvideoshare.description LIKE '%" . get_query_var('s') . "%') OR " . $restOfQuery ." GROUP BY " . $wpdb->posts . ".ID"; 

    // Return revised WHERE clause 
    var_dump($where); 
    return $where; 
} 

Als ich hinzufügen, das es nichts zurückliefert weder aus noch Beiträgen von hdflvvideoshare. Es zeigt mir "No results".

var_dump($where); Rückkehr dies:

string(625) " AND (((wpdu_hdflvvideoshare.description LIKE '%driver%') OR (((wpdu_posts.post_title LIKE '%driver%') OR (wpdu_posts.post_content LIKE '%driver%'))) OR ((tter.name LIKE '%driver%')) OR ((tter.slug LIKE '%driver%')) OR ((ttax.description LIKE '%driver%')) OR ((m.meta_value LIKE '%driver%')) OR ((wpdu_posts.post_excerpt LIKE '%driver%')) OR (((cmt.comment_content LIKE '%driver%')) AND cmt.comment_approved = '1') OR ((u.display_name LIKE '%driver%')))) AND (wpdu_posts.post_password = '') AND wpdu_posts.post_type IN ('page', 'post', 'videogallery') AND (wpdu_posts.post_status = 'publish') GROUP BY wpdu_posts.ID" string(541) "(((wpdu_posts.post_title LIKE '%driver%') OR (wpdu_posts.post_content LIKE '%driver%'))) OR ((tter.name LIKE '%driver%')) OR ((tter.slug LIKE '%driver%')) OR ((ttax.description LIKE '%driver%')) OR ((m.meta_value LIKE '%driver%')) OR ((wpdu_posts.post_excerpt LIKE '%driver%')) OR (((cmt.comment_content LIKE '%driver%')) AND cmt.comment_approved = '1') OR ((u.display_name LIKE '%driver%')))) AND (wpdu_posts.post_password = '') AND wpdu_posts.post_type IN ('page', 'post', 'videogallery') AND (wpdu_posts.post_status = 'publish')" 

Was falsch ist. Warum kann ich das nicht zur Arbeit bringen?

Update: Ich glaube, dass dies die vollständige Abfrage ist die

SELECT DISTINCT SQL_CALC_FOUND_ROWS wpdu_posts.* FROM wpdu_posts LEFT JOIN wpdu_hdflvvideoshare LEFT JOIN wpdu_term_relationships AS trel ON (wpdu_posts.ID = trel.object_id) LEFT JOIN wpdu_term_taxonomy AS ttax ON ((ttax.taxonomy = 'category' OR ttax.taxonomy = 'post_tag' OR ttax.taxonomy = 'post_format' OR ttax.taxonomy = 'bp_member_type' OR ttax.taxonomy = 'bp-email-type') AND trel.term_taxonomy_id = ttax.term_taxonomy_id) LEFT JOIN wpdu_terms AS tter ON (ttax.term_id = tter.term_id) LEFT JOIN wpdu_comments AS cmt ON (cmt.comment_post_ID = wpdu_posts.ID) LEFT JOIN wpdu_postmeta AS m ON (wpdu_posts.ID = m.post_id) LEFT JOIN wpdu_users AS u ON (wpdu_posts.post_author = u.ID) WHERE 1=1 AND (((((wpdu_hdflvvideoshare.description LIKE '%driver%') OR (((wpdu_posts.post_title LIKE '%driver%') OR (wpdu_posts.post_content LIKE '%driver%'))) OR ((tter.name LIKE '%driver%')) OR ((tter.slug LIKE '%driver%')) OR ((ttax.description LIKE '%driver%')) OR ((m.meta_value LIKE '%driver%')) OR ((wpdu_posts.post_excerpt LIKE '%driver%')) OR (((cmt.comment_content LIKE '%driver%')) AND cmt.comment_approved = '1') OR ((u.display_name LIKE '%driver%')))) AND (wpdu_posts.post_password = '') AND wpdu_posts.post_type IN ('page', 'post', 'videogallery') AND (wpdu_posts.post_status = 'publish' OR wpdu_posts.post_type = 'attachment' OR wpdu_posts.post_status = 'draft') GROUP BY wpdu_posts.ID) AND post_type != 'revision') AND post_status != 'future' ORDER BY wpdu_posts.post_title LIKE '%driver%' DESC, wpdu_posts.post_date DESC LIMIT 0, 10 
+0

Was ist der vollständige SQL-Befehl, der fehlschlägt? Ihr var_dump ist keine abgeschlossene SQL-Anweisung –

+0

Wie kann ich die vollständige Abfrage sehen? –

+0

var_dump die Variable, die die gesamte SQL-Anweisung enthält. –

Antwort

2

Ihre Anfrage hat einen GROUP BY Zustand im Inneren der WHERE Klausel erzeugt wird. Es kann andere Probleme geben, aber das wird sicherlich sicherstellen, dass Sie einen Syntaxfehler bekommen.