• Resolved fenix1987

    (@fenix1987)


    I encountered line of code below:
    add_action( ‘posts_selection‘, ‘cipnl_check_post’ );

    and wondering when does posts_selection happen? I already did some research and did not find any useful information telling about it. hope someone can help me on this. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter fenix1987

    (@fenix1987)

    can anybody help? ??

    GRAQ

    (@graq)

    Sometimes you need to dig through the code a little:

    From https://adambrown.info/p/wp_hooks/hook/posts_selection?version=3.1&file=wp-includes/query.php

    // Announce current selection parameters.  For use by caching plugins.
    do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
    Thread Starter fenix1987

    (@fenix1987)

    yeah, I’ve seen that one already. so that is executed every time a query is made? sorry as I didn’t understand it much. Thanks for the response btw..

    GRAQ

    (@graq)

    Whenever do_action() is called, all the add_action()s get invoked.

    Imagine that you want to do X when Y happens. The core team have in their function the line do_action('y_has_happened', $with_this_data);

    You can write in your theme or plugin:

    add_action('y_has_happened', 'my_function_when_y_happens');
    function my_function_when_y_happens($happened_with_this_data){
      // Do X (with the data).
    }

    Hence them being ‘hooks’ they are points that allow theme/plugin writers to hook into that point.

    Thread Starter fenix1987

    (@fenix1987)

    that makes sense now. Thanks a lot!

    GRAQ

    (@graq)

    Glad to help. Don’t forget to mark the topic resolved ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘meaning of posts_selection in add_action’ is closed to new replies.