Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Ajay

    (@ajay)

    The list of post IDs are one of the pending features to be implemented either in core or via an addon

    Are you filtering the where clause to add the exceptions?

    https://github.com/WebberZone/better-search/blob/92a77cfcee9d448a8d3f628e1b291b8f5bc01c87/includes/query.php#L151

    Thread Starter stewagner

    (@stewagner)

    no, I added the above in the SQL statement in better-search.php in function bsearch_install:

    SELECT blog_id FROM $wpdb->blogs WHERE archived = ‘0’ AND spam = ‘0’ AND deleted = ‘0’ AND NOT IN (‘1877 2020’)

    How would I amend the where statement in query.php?

    That’s not really the way to do it stewagner,

    Ajay is pointing you to the where filter.

    You can use it like this:

    function my_custom_posts_where($where) {
    	// Edit the where part of the query, add the NOT IN part
    	$where .= "AND wp_posts.ID NOT IN (3521, 3519) ";
    	// Return the where part to the plugin
    	return $where;
    }
    add_filter('bsearch_posts_where', 'my_custom_posts_where');

    Although I’m not entirely sure the part I added to your query will fix it, this is the way to add parts to the query.

    Oh and by the way, you write this code in your functions.php of your theme (if you are not using your own theme, use a child theme to make sure your overwrite will not be removed in the next update of your theme).

    Thread Starter stewagner

    (@stewagner)

    I added that function to the end of my theme’s functions.php (with my IDs) but then search stopped finding anything. So I threw it out again.
    ?

    Plugin Author Ajay

    (@ajay)

    jifuss’ function is the right way to do it. Does this work?

    function my_custom_posts_where($where) {
    	// Edit the where part of the query, add the NOT IN part
    	$where .= " AND {$wpdb->posts}.ID NOT IN (3521, 3519) ";
    	// Return the where part to the plugin
    	return $where;
    }
    add_filter('bsearch_posts_where', 'my_custom_posts_where');
    Thread Starter stewagner

    (@stewagner)

    … no, same result: every search results in 0 hits ??
    Please check again.

    Plugin Author Ajay

    (@ajay)

    Can you please install query monitory plugin and then check the search results page and see what queries are generated?

    Thread Starter stewagner

    (@stewagner)

    I uploaded a screenshot of the result here:

    Is it want you wanted?

    Thread Starter stewagner

    (@stewagner)

    Something more like this probably.

    Thread Starter stewagner

    (@stewagner)

    aha, please reload the screenshot!

    Thread Starter stewagner

    (@stewagner)

    … one “.” too much right?

    Thread Starter stewagner

    (@stewagner)

    or is “$wpdb->posts” undefined?

    Plugin Author Ajay

    (@ajay)

    That’s right. I missed a line.
    Please add global $wpdb; as the first line after the function line

    Thread Starter stewagner

    (@stewagner)

    BINGO – thank you very much!!

    Will you implement a more convenient ID exclusion in settings soon?

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Exclude pages from search’ is closed to new replies.