• Hi, I’m working on a site running version 3.5.1 of WordPress with the WP E-commerce plugin installed. The client wanted to exclude a number of posts from the search results page, so I installed the Search Exclude plugin (https://www.ads-software.com/plugins/search-exclude/). I gave the plugin a test, but it didn’t seem to do anything.

    After a bit of digging, I found that when WP E-commerce was active, it was stopping the Search Exclude plugin from working.

    I dumped the functions hooked to the pre_get_posts filter:

    Array
    (
        [10] => Array
            (
                [0000000021703a1a0000000023da960esearchFilter] => Array
                    (
                        [function] => Array
                            (
                                [0] => SearchExclude Object
                                    (
                                    )
    
                                [1] => searchFilter
                            )
    
                        [accepted_args] => 1
                    )
    
                [0000000021703b180000000023da960eget_posts] => Array
                    (
                        [function] => Array
                            (
                                [0] => WPSC_Hide_subcatsprods_in_cat Object
                                    (
                                        [q] =>
                                    )
    
                                [1] => get_posts
                            )
    
                        [accepted_args] => 1
                    )
    
            )
    
        [1] => Array
            (
                [_wpsc_pre_get_posts_reset_taxonomy_globals] => Array
                    (
                        [function] => _wpsc_pre_get_posts_reset_taxonomy_globals
                        [accepted_args] => 1
                    )
    
            )
    
        [8] => Array
            (
                [wpsc_split_the_query] => Array
                    (
                        [function] => wpsc_split_the_query
                        [accepted_args] => 1
                    )
    
            )
    
    )

    _wpsc_pre_get_posts_reset_taxonomy_globals and wpsc_split_the_query appear to run fine, however, the last two aren’t running at all.

    After a bit of playing, I found that at the end of the wpsc_split_the_query method, there is the following:

    remove_filter( 'pre_get_posts', 'wpsc_split_the_query', 8 );

    If I comment that line out, all of the hooked functions run. Leave it in, and only 2/4 run. I tried outputting the list of hooked functions again, after the do_action, and the two functions that didn’t run were still hooked, so they hadn’t been removed, but just didn’t run :/

    Does anyone know why that would be the case?

Viewing 1 replies (of 1 total)
  • Thread Starter scrooby

    (@scrooby)

    Bit of a follow up, I’ve found that if I change the priority of the Search Exclude plugin filter to anywhere from 1-8, it works and all functions are executed.

    A quick fix, but it involves me editing the Search Exclude plugin, which isn’t ideal. It would also be interesting to know why the remove_filter would be causing this issue.

Viewing 1 replies (of 1 total)
  • The topic ‘pre_get_posts filter not running’ is closed to new replies.