• Resolved acquacalda

    (@acquacalda)


    Hello,
    I need help perfecting my search forms.

    I have two different search forms within my site and I would like each of them NOT to show certain results.
    Unfortunately I cannot do this with the taxonomy because the objects I want to exclude are the Projects of the Divi theme whose categories and tags are not recognized in the categories and tags of WordPress.

    I was wondering if it was possible, even using php, to exclude certain page ids from each of the two modules.

    Can anyone help me please?
    Thanks in advance for the help

Viewing 1 replies (of 1 total)
  • Plugin Author Sumit Singh

    (@5um17)

    Hi,

    This feature is under development. But I can provide you a snippet which you can add to theme functions.php

    
    /**
     * Exclude some posts from search results.
     * 
     * @param WP_Query $q
     */
    function wpes_support_15083978($q) {
    	// Replace 5 with search setting ID and false for global setting.
    	if (function_exists('WPES') && WPES()->is_search($q) && WPES()->current_setting_id == 5) {
    		$q->set('post__not_in', [1,2]); //replace 1 and 2 with post/page IDs
    	}
    }
    add_action('pre_get_posts', 'wpes_support_15083978');
    

    Replace the 5 with search setting ID and replace 1 and 2 with your posts/pages IDs those you want to exclude.

    Hope it helps.

Viewing 1 replies (of 1 total)
  • The topic ‘How to esclude resaults from search with pages id’ is closed to new replies.