• markhof

    (@markhof)


    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)
  • Joy

    (@joyously)

    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

    (@jdembowski)

    Forum Moderator and Brute Squad

    Which theme?

    Thread Starter markhof

    (@markhof)

    Avada

    Thread Starter markhof

    (@markhof)

    avada/includes/class-avada-init.php

    line 496

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    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. 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.