• Function hooked on pre_get_posts is executed before a function hooked on init action.

    I’ve checked WordPress actions sequence and init action is triggered before pre_get_posts, so my logic is functions hooked on init should be executed firstly against functions hooked on pre_get_posts.

    I’ve installed a plugin which shows the sequence of executed actions and the init action is executed firstly, which is okay.

    I tried to debug it, but unfortunately without success. Here is my debugging flow:
    I’ve checked with xdebug breaking points the sequence of actions and functions execution. I set 4 breaking points:

    1. do_action( ‘init’ ) at line 353 in wp-settings.php
    2. do_action_ref_array( ‘pre_get_posts’, array( &$this ) ) at line 2396 in query.php
    3. function A which executes on init
    4. function B which executes on pre_get_posts

    The result is:

    1. do_action( ‘init’ ) is called firstly
    2. do_action_ref_array( ‘pre_get_posts’, array( &$this ) ) is called secondly
    3. and the strange part is here function B is called before A
    4. Function A is called after B

    So what can be the reason function B is called before A?

    Thank you in advance!

  • The topic ‘Hooks sequence problem’ is closed to new replies.