Title: hook to replace a function question
Last modified: February 23, 2019

---

# hook to replace a function question

 *  [markhof](https://wordpress.org/support/users/markhof/)
 * (@markhof)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/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
    -  This topic was modified 7 years, 3 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11229383)
 * What a mess.
    Your theme shouldn’t even have a search filter. It’s plugin territory.
   I would call `remove_filter()` for the parent theme’s function. Then add your
   child theme function, like the parent theme does. (Although, it might not be 
   quite right because child functions.php runs before the parent functions.php,
   so you may need to remove the parent filter if a different place.)
 * But this theme doesn’t show up on the WordPress themes page, so you should be
   asking this question somewhere else.
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11230826)
 * Which theme?
 *  Thread Starter [markhof](https://wordpress.org/support/users/markhof/)
 * (@markhof)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11231579)
 * Avada
 *  Thread Starter [markhof](https://wordpress.org/support/users/markhof/)
 * (@markhof)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11231605)
 * avada/includes/class-avada-init.php
 * line 496
 *  Moderator [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * (@jdembowski)
 * Forum Moderator and Brute Squad
 * [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11238060)
 * For pro or commercial product support please contact the author directly on their
   site. This includes any pre-sales topics as well.
 * As the author is aware, commercial products are [not supported in these forums](https://wordpress.org/support/guidelines/#do-not-post-about-commercial-products).
   I am sure they will have no problem supporting you there.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘hook to replace a function question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [Jan Dembowski](https://wordpress.org/support/users/jdembowski/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/hook-to-replace-a-function-question/#post-11238060)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
