• Resolved tahtu

    (@tahtu)


    I’m using the pre_get_posts action to limit the search results further more. Without Better Search, I can detect the search reqeusts inside of it with $query->is_search(). This does not longer work after installing Better Search. Can you fix this issue?

    Example:
    add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ );
    function my_pre_get_posts( $query ) {
    if ( $query->is_search() ) {

    }
    }

    I want to limit the search results to some categories only. Without Better search, I can do this with $query->set( ‘cat’, array(1, 2, 3) ). But after installing Better Search, this does not work further more. Right now, I don’t have any search result. Can you fix this issue too?

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

    (@ajay)

    Are you in a position to debug what the query that is generated when you’re doing this? You’ll need Query Monitor plugin for this.

    I had to run some recent changes which is likely to cause this as the previous version had unnecessary additions to WHERE clauses which interfered with Better Search output.

    Thread Starter tahtu

    (@tahtu)

    Today I installed Relevanssi to compare it with Better Search. Relevanssi is much more complex and has a lot of additional features. But Better Search is much smaller and let do MySQL the relevance calculation. Both solutions have advantages.

    So in the moment, it’s not easy for my to show the used SQL query to you, since I uninstalled Better Search for the moment.

    But like I suggested to use the WP_Query class to you inside an other topic in this forum a few minutes before, I suggest to you: Do not investigate more time into your SQL generation at all. You waste a lot of time with this and you never can offer all the same features like WP_Query can do. Additional Webmaster like me should know the WP_Query implementation and its filtering with its pre_get_posts action.

    Because of this, I will not support you with your own SQL generation, even I have installed the Query Monitor and I know SQL good from previous jobs.

    The disvantage of your own SQL gereration implementation forced me to analyse your PHP code to figure out, how I can implement my search restriction to some categories. After that, I had to find out, how WordPress implemented the category <-> post relationship and wrote more SQL code, than I could do this with the well documented WP_Query class.

    So with your own SQL generation, you not just wasted a lot of your time, you wasted also a lot of my time. Because of this, I let you know so detailed my knowledge about the WP_Query class to not to waste further time.

    I hope you understood my suggestions, and why I don’t support you with your question.

    I still don’t know, what is better: Better Search or Relevanssi. Since Better Search let do MySQL the job of calculating and apply it with, I believe Better Search has advantages againt Relevanssi too.

    But maybe I wrong… ??

    Plugin Author Ajay

    (@ajay)

    I’ve responded to the other post in the forum. I’ll close this for now and we can keep the thread going there.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem with the pre_get_posts action’ is closed to new replies.