Add_Custom_Fields_To_Search::cf_search_join( string $join )

cf_search_join


Description Description

Join posts and postmeta tables

See also See also


Top ↑

Parameters Parameters

$join

(string) (Required)


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-add-custom-fields-to-search.php

		function cf_search_join( $join ) {
		    global $wpdb;

			if ( ! is_search() || $this->is_media_library() ) {
				return $join;
			}

			//join to search post meta values like year, make, model, trim, etc
			$join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';

			//these joins are so taxonomy terms like Sport Utility Vehicle => suv are included
			$join .= 'LEFT JOIN ' . $wpdb->term_relationships . ' tr ON ' . $wpdb->posts . '.ID = tr.object_id '
				. 'INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON tt.term_taxonomy_id = tr.term_taxonomy_id '
				. 'INNER JOIN ' . $wpdb->terms . ' t ON t.term_id = tt.term_id ';

			return $join;
		}