• Resolved threadi

    (@threadi)


    Hi,

    I have noticed that TranslatePress affects searches in languages other than the main language. This may be suitable for many projects – for what I am working on it is not desired.

    I would like to disable this hook:

    $this->loader->add_filter( 'pre_get_posts', $this->search, 'trp_search_filter', 99999999 );

    My attempt to do this is in the functions.php of my child theme:

    function custom_remove_trp_hooks( $loader_obj ) {
    $loader_obj->remove_hook( 'pre_get_posts' );
    }
    add_action( 'trp_before_running_hooks', 'custom_remove_trp_hooks', 10, 1 );

    Unfortunately, this is executed AFTER TRP_Hooks_Loader::run(), so it doesn’t take effect at all.

    What can I do to disable the hook?

    Thanks in advance ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi there,

    Thank you for your message and observations.

    You’re partially correct in your understanding.

    The hook ‘trp_before_running_hooks’ does indeed run before the functions.php in your theme. This is the reason why the code you added there doesn’t have any effect.

    However, it’s important to note that this situation occurs only if the code is added in the theme’s functions.php file.

    The code you provided would actually work perfectly if placed in a new plugin rather than in the theme.

    In case you specifically need to include this code within the theme’s functions.php file, you can use the following code instead:

    add_action(‘init’, ‘trpc_remove_search_hook’);
    function trpc_remove_search_hook(){
    $trp = TRP_Translate_Press::get_trp_instance();
    $trp_search = $trp->get_component(‘search’);
    remove_filter(‘pre_get_posts’, array($trp_search,’trp_search_filter’), 99999999 );
    }

    By using this code, you’re creating an action that triggers upon initialization, which will then proceed to remove the search filter.

    We’ve updated our documentation to reflect this particular scenario and provide clear guidance on removing TranslatePress hooks.

    Here’s the link for reference: https://translatepress.com/docs/developers/remove-translatepress-hooks/

    Please let me know if you have any other questions or require further assistance. We’re here to help!

    Best regards,

    Thread Starter threadi

    (@threadi)

    Hey,

    thank you for your answer. This helped me a lot and I was able to implement my wish with the above code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Disable changes on search-query’ is closed to new replies.