{"id":1321889,"date":"2017-07-16T07:26:23","date_gmt":"2017-07-16T14:26:23","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/"},"modified":"2017-07-16T07:26:23","modified_gmt":"2017-07-16T14:26:23","slug":"problem-with-search-with-custom-fields","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/","title":{"rendered":"Problem with search with Custom Fields"},"content":{"rendered":"<p>Hey,<\/p>\n<p>I use Event Calendar Pro and Filter Bar.<br \/>\nI&#8217;m having a problem with Custom Fields added to the search results.<br \/>\nI read and followed this topic : https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/<\/p>\n<p>I can now find my stuff in the event list in the WordPress Administration, but not on my website through the tribe-bar-search.<\/p>\n<p>Here is the code I pasted in my theme&#8217;s functions.php :<\/p>\n<pre><code>\/**\n * Extend WordPress search to include custom fields\n *\n * http:\/\/adambalee.com\n *\/\n\n\/**\n * Join posts and postmeta tables\n *\n * http:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/posts_join\n *\/\nfunction cf_search_join( $join ) {\n    global $wpdb;\n\n\/* https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/ *\/\nif ( is_search() || !empty( $_REQUEST[&#039;tribe-bar-search&#039;] ) ) {\n        $join .=&#039; LEFT JOIN &#039;.$wpdb-&gt;postmeta. &#039; ON &#039;. $wpdb-&gt;posts . &#039;.ID = &#039; . $wpdb-&gt;postmeta . &#039;.post_id &#039;;\n    }\n    \n    return $join;\n}\nadd_filter(&#039;posts_join&#039;, &#039;cf_search_join&#039; );\n\n\/**\n * Modify the search query with posts_where\n *\n * http:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/posts_where\n *\/\nfunction cf_search_where( $where ) {\n    global $wpdb;\n   \n\/* https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/ *\/\nif ( is_search() || !empty( $_REQUEST[&#039;tribe-bar-search&#039;] ) ) {\n        $where = preg_replace(\n            &quot;\/\\(\\s*&quot;.$wpdb-&gt;posts.&quot;.post_title\\s+LIKE\\s*(\\&#039;[^\\&#039;]+\\&#039;)\\s*\\)\/&quot;,\n            &quot;(&quot;.$wpdb-&gt;posts.&quot;.post_title LIKE $1) OR (&quot;.$wpdb-&gt;postmeta.&quot;.meta_value LIKE $1)&quot;, $where );\n    }\n\n    return $where;\n}\nadd_filter( &#039;posts_where&#039;, &#039;cf_search_where&#039; );\n\n\/**\n * Prevent duplicates\n *\n * http:\/\/codex.wordpress.org\/Plugin_API\/Filter_Reference\/posts_distinct\n *\/\nfunction cf_search_distinct( $where ) {\n    global $wpdb;\n\n\/* https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/ *\/\nif ( is_search() || !empty( $_REQUEST[&#039;tribe-bar-search&#039;] ) ) {\n        return &quot;DISTINCT&quot;;\n    }\n\n    return $where;\n}\nadd_filter( &#039;posts_distinct&#039;, &#039;cf_search_distinct&#039; );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-1321889","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Problem with search with Custom Fields -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Problem with search with Custom Fields -\" \/>\n<meta property=\"og:description\" content=\"Hey, I use Event Calendar Pro and Filter Bar. I&#8217;m having a problem with Custom Fields added to the search results. I read and followed this topic : https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/ I can now find my stuff in the event list in the WordPress Administration, but not on my website through the tribe-bar-search. Here is the code [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/\",\"name\":\"Problem with search with Custom Fields -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-07-16T14:26:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Filter Bar\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/filter-bar\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Problem with search with Custom Fields\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Problem with search with Custom Fields -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/","og_locale":"en_US","og_type":"article","og_title":"Problem with search with Custom Fields -","og_description":"Hey, I use Event Calendar Pro and Filter Bar. I&#8217;m having a problem with Custom Fields added to the search results. I read and followed this topic : https:\/\/theeventscalendar.com\/support\/forums\/topic\/how-to-include-custom-fields-in-search\/ I can now find my stuff in the event list in the WordPress Administration, but not on my website through the tribe-bar-search. Here is the code [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/","name":"Problem with search with Custom Fields -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-07-16T14:26:23+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/problem-with-search-with-custom-fields\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Filter Bar","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/filter-bar\/"},{"@type":"ListItem","position":5,"name":"Problem with search with Custom Fields"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1321889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1321889\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1321889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}