• Resolved widescreen

    (@widescreen)


    Hi, great plugin, thanks.

    I have a custom table with about 350.000 rows.

    I did modify the search
    – add_filter(‘posts_join’, ‘mysearch_join’ );
    – function mysearch_join{
    if( is_search() ) {
    $join .= ” INNER JOIN mytable ON $wpdb->posts.mycolumn = mytable.mycolumn }
    }

    Database query time: 0.0648s
    But page takes about 5secs to load.

    Unfortunately this query (that makes the difference in time) doesn’t show up in Query-monitor.

    Am I forgetting something?

    [PS I did run the query in phpMyAdmin and it took about 3.5 sec. According to your experience is it a reasonable time for the size of my custom table?]

    Thanks for your support!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author John Blackbourn

    (@johnbillion)

    WordPress Core Developer

    Thanks for the message. Your code above is incomplete. The following works as expected for me and shows up in QM:

    add_filter('posts_join', 'mysearch_join' );
    function mysearch_join( $join ) {
    	global $wpdb;
    	if ( is_search() ) {
    		$join .= " INNER JOIN mytable ON $wpdb->posts.mycolumn = mytable.mycolumn";
    	}
    	return $join;
    }
    

    Result:

    A query which takes 3.5 seconds is not a reasonable time. If your site gets a lot of traffic then it’ll kill your MySQL server. I would suggest splitting the query into two separate queries if possible, to avoid the join.

    Thread Starter widescreen

    (@widescreen)

    Thanks John! Splitting the query was the way!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom search query not showing’ is closed to new replies.