{"id":11229126,"date":"2019-02-20T22:16:50","date_gmt":"2019-02-20T22:16:50","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/hook-to-replace-a-function-question\/"},"modified":"2019-02-23T02:35:05","modified_gmt":"2019-02-23T02:35:05","slug":"hook-to-replace-a-function-question","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/hook-to-replace-a-function-question\/","title":{"rendered":"hook to replace a function question"},"content":{"rendered":"<p>Hi,<\/p>\n<p>I&#8217;m looking to alter a function in my child from a parent theme, and having some trouble writing the hook. Any help would be appreciated.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nhere&#8217;s the function from the parent theme<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<pre><code>\r\npublic function modify_search_filter( $query ) {\r\n\tif ( is_search() &amp;&amp; $query-&gt;is_search ) {\r\n\t\tif ( isset( $_GET ) &amp;&amp; ( 2 &lt; count( $_GET ) || ( 2 == count( $_GET ) &amp;&amp; ! isset( $_GET[&#039;lang&#039;] ) ) ) ) {\r\n\t\t\treturn $query;\r\n\t\t}\r\n\r\n\t\t$search_content = Avada()-&gt;settings-&gt;get( &#039;search_content&#039; );\r\n\r\n\t\tif ( &#039;all_post_types_no_pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, array( &#039;post&#039;, &#039;avada_portfolio&#039;, &#039;product&#039;, &#039;tribe_events&#039; ) );\r\n\t\t\r\n\t\t} elseif ( &#039;Only Posts&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;post&#039; );\r\n\t\t} elseif ( &#039;portfolio_items&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;avada_portfolio&#039; );\r\n\t\t} elseif ( &#039;Only Pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;page&#039; );\r\n\t\t} elseif ( &#039;woocommerce_products&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;product&#039; );\r\n\t\t} elseif ( &#039;tribe_events&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;tribe_events&#039; );\r\n\t\t}\r\n\t}\r\n\treturn $query;\r\n}\r\n\r\n---------------------------\r\nthis is what I want \r\n---------------------------\r\n\r\npublic function modify_search_filter( $query ) {\r\n\tif ( is_search() &amp;&amp; $query-&gt;is_search ) {\r\n\t\tif ( isset( $_GET ) &amp;&amp; ( 2 &lt; count( $_GET ) || ( 2 == count( $_GET ) &amp;&amp; ! isset( $_GET[&#039;lang&#039;] ) ) ) ) {\r\n\t\t\treturn $query;\r\n\t\t}\r\n\r\n\t\t$search_content = Avada()-&gt;settings-&gt;get( &#039;search_content&#039; );\r\n\r\n\t\tif ( &#039;all_post_types_no_pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, array( &#039;page&#039;, &#039;post&#039;, &#039;people&#039; ) );\r\n\t\t\r\n\t\t} elseif ( &#039;Only Posts&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;post&#039; );\r\n\t\t} elseif ( &#039;portfolio_items&#039; === $search_content ) {\r\n\t\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;avada_portfolio&#039; );\r\n\t\t} elseif ( &#039;Only Pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;page&#039; );\r\n\t\t} elseif ( &#039;woocommerce_products&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;product&#039; );\r\n\t\t} elseif ( &#039;tribe_events&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;tribe_events&#039; );\r\n\t\t}\r\n\t}\r\n\treturn $query;\r\n}\r\n\r\n---------------------------\r\nthis is what I&#039;ve tried in my function file (and it didn&#039;t work) \r\n---------------------------\r\n\r\nadd_filter( &#039;modify_search_filter&#039;, &#039;my_modify_search_filter&#039;, 11, 2 );\r\n\r\nfunction my_modify_search_filter( $query ) {\r\n\tif ( is_search() &amp;&amp; $query-&gt;is_search ) {\r\n\t\tif ( isset( $_GET ) &amp;&amp; ( 2 &lt; count( $_GET ) || ( 2 == count( $_GET ) &amp;&amp; ! isset( $_GET[&#039;lang&#039;] ) ) ) ) {\r\n\t\t\treturn $query;\r\n\t\t}\r\n\r\n\t\t$search_content = Avada()-&gt;settings-&gt;get( &#039;search_content&#039; );\r\n\r\n\t\tif ( &#039;all_post_types_no_pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, array( &#039;page&#039;, &#039;post&#039;, &#039;people&#039; ) );\r\n\t\t\r\n\t\t} elseif ( &#039;Only Posts&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;post&#039; );\r\n\t\t} elseif ( &#039;portfolio_items&#039; === $search_content ) {\r\n\t\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;avada_portfolio&#039; );\r\n\t\t} elseif ( &#039;Only Pages&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;page&#039; );\r\n\t\t} elseif ( &#039;woocommerce_products&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;product&#039; );\r\n\t\t} elseif ( &#039;tribe_events&#039; === $search_content ) {\r\n\t\t\t$query-&gt;set( &#039;post_type&#039;, &#039;tribe_events&#039; );\r\n\t\t}\r\n\t}\r\n\treturn $query;\r\n}\r\n<\/code><\/pre>\n<p>Thanks<br \/>\nMark<\/p>\n","protected":false},"template":"","class_list":["post-11229126","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11229126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11229126\/revisions"}],"predecessor-version":[{"id":11230820,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11229126\/revisions\/11230820"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11229126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}