hook to replace a function question
-
Hi,
I’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.
—————————————
here’s the function from the parent theme
————————————–public function modify_search_filter( $query ) { if ( is_search() && $query->is_search ) { if ( isset( $_GET ) && ( 2 < count( $_GET ) || ( 2 == count( $_GET ) && ! isset( $_GET['lang'] ) ) ) ) { return $query; } $search_content = Avada()->settings->get( 'search_content' ); if ( 'all_post_types_no_pages' === $search_content ) { $query->set( 'post_type', array( 'post', 'avada_portfolio', 'product', 'tribe_events' ) ); } elseif ( 'Only Posts' === $search_content ) { $query->set( 'post_type', 'post' ); } elseif ( 'portfolio_items' === $search_content ) { $query->set( 'post_type', 'avada_portfolio' ); } elseif ( 'Only Pages' === $search_content ) { $query->set( 'post_type', 'page' ); } elseif ( 'woocommerce_products' === $search_content ) { $query->set( 'post_type', 'product' ); } elseif ( 'tribe_events' === $search_content ) { $query->set( 'post_type', 'tribe_events' ); } } return $query; } --------------------------- this is what I want --------------------------- public function modify_search_filter( $query ) { if ( is_search() && $query->is_search ) { if ( isset( $_GET ) && ( 2 < count( $_GET ) || ( 2 == count( $_GET ) && ! isset( $_GET['lang'] ) ) ) ) { return $query; } $search_content = Avada()->settings->get( 'search_content' ); if ( 'all_post_types_no_pages' === $search_content ) { $query->set( 'post_type', array( 'page', 'post', 'people' ) ); } elseif ( 'Only Posts' === $search_content ) { $query->set( 'post_type', 'post' ); } elseif ( 'portfolio_items' === $search_content ) { $query->set( 'post_type', 'avada_portfolio' ); } elseif ( 'Only Pages' === $search_content ) { $query->set( 'post_type', 'page' ); } elseif ( 'woocommerce_products' === $search_content ) { $query->set( 'post_type', 'product' ); } elseif ( 'tribe_events' === $search_content ) { $query->set( 'post_type', 'tribe_events' ); } } return $query; } --------------------------- this is what I've tried in my function file (and it didn't work) --------------------------- add_filter( 'modify_search_filter', 'my_modify_search_filter', 11, 2 ); function my_modify_search_filter( $query ) { if ( is_search() && $query->is_search ) { if ( isset( $_GET ) && ( 2 < count( $_GET ) || ( 2 == count( $_GET ) && ! isset( $_GET['lang'] ) ) ) ) { return $query; } $search_content = Avada()->settings->get( 'search_content' ); if ( 'all_post_types_no_pages' === $search_content ) { $query->set( 'post_type', array( 'page', 'post', 'people' ) ); } elseif ( 'Only Posts' === $search_content ) { $query->set( 'post_type', 'post' ); } elseif ( 'portfolio_items' === $search_content ) { $query->set( 'post_type', 'avada_portfolio' ); } elseif ( 'Only Pages' === $search_content ) { $query->set( 'post_type', 'page' ); } elseif ( 'woocommerce_products' === $search_content ) { $query->set( 'post_type', 'product' ); } elseif ( 'tribe_events' === $search_content ) { $query->set( 'post_type', 'tribe_events' ); } } return $query; }
Thanks
Mark
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘hook to replace a function question’ is closed to new replies.