can I pass arguments to my function through add_action?

后端 未结 13 2161
慢半拍i
慢半拍i 2020-11-29 01:07

can I do something like that? to pass arguments to my function? I already studied add_action doc but did not figure out how to do it. What the exact syntax to pass two argum

13条回答
  •  独厮守ぢ
    2020-11-29 01:30

    Basically the do_action is placed where the action should be executed, and it needs a name plus your custom parameters.

    When you come to call the function using add_action, pass the name of your do_action() as your first argument, and the function name as the second. So something like:

    function recent_post_by_author($author,$number_of_posts) {
      some commands;
    }
    add_action('get_the_data','recent_post_by_author',10,'author,2');
    

    This is where it's executed

    do_action('get_the_data',$author,$number_of_posts);
    

    Should hopefully work.

提交回复
热议问题