Seperate site search from GD v2 search

This topic contains 5 replies, has 2 voices, and was last updated by  Alex Rollin 5 years, 7 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: ,

  • Author
    Posts
  • #477758

    2cool4school
    Expired Member
    Post count: 41

    is it possible that the general site search can be implemented in a way that does not try to search the directory?

    we have multiple non directory pages we would like users to be able to search

    #477786

    Alex Rollin
    Moderator
    Post count: 27815

    I have flagged your question for the developers who are looking into a solution.

    #477795

    Alex Rollin
    Moderator
    Post count: 27815

    Try this:

    
    
    
    /**
     * Exclude GD CPTs from WP Search.
     */
    function gd_snippet_wp_search_exclude_cpts( $wp_query ) {
    	if ( is_admin() || empty( $wp_query ) ) {
    		return;
    	}
    
    	if ( ! ( $wp_query->is_main_query() && $wp_query->is_search() ) ) {
    		return;
    	}
    
    	if ( geodir_is_page( 'search' ) ) {
    		return;
    	}
    
    	$in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) );
    	$post_types = geodir_get_posttypes();
    
    	if ( ! empty( $in_search_post_types ) && ! empty( $post_types ) ) {
    		$search_post_types = array();
    
    		foreach ( $in_search_post_types as $post_type ) {
    			if ( ! in_array( $post_type, $post_types ) ) {
    				$search_post_types[] = $post_type;
    			}
    		}
    
    		$wp_query->set( 'post_type', $search_post_types );
    	}
    }
    add_action( 'pre_get_posts', 'gd_snippet_wp_search_exclude_cpts', 10 );
    

    You can add that as a snippet with the code snippets plugin:
    https://wpgeodirectory.com/docs/useful-plugins/#snippets

    #477796

    2cool4school
    Expired Member
    Post count: 41

    ive added it but it still only seems to search GD

    #477800

    2cool4school
    Expired Member
    Post count: 41

    actually – let me add to that
    it kind of works in that if i enter a search it finds the relevant article but only displays the title along with the directory search page

    in the attachment you will see what i mean
    i created a search from a search widget on a blog page and it displays what you see in the attachement

    #477838

    Alex Rollin
    Moderator
    Post count: 27815

    Ah, I misunderstood.

    Let me clarify.

    That search bar is for the directory and will only ever search GD listings.

    However you can use WP Search as a widget, and use the snippet above to make sure that GD Listings don’t get returned in WP Search.

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount