can one do something of that nature? to pass through arguments to my function? I already analyzed add_action doc but didn't learn how to get it done. Exactly what the exact syntax to pass through two arguments would seem like. Particularly how you can pass text &lifier integer arguments.

function recent_post_by_author($author,$number_of_posts) {
  some commands;


it appears in my experience that it's done in some way through do_action but exactly how? :-)

Essentially the do_action is positioned in which the action ought to be performed, also it requires a title as well as your custom parameters.

Whenever you arrived at call the function using add_action, pass the title of the do_action() as the first argument, and also the function title because the second. So something similar to:

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.

I went in to the same problem and solved it by utilizing global variables. Like so:

global $myvar;
$myvar = value;
add_action('hook', 'myfunction');

function myfunction() {
    global $myvar;

A little sloppy however it works.

I have a similar problem. I solved it having a global variable... But that simply smells horrible!

Yes, you are able to (however the documentation for this is horrible).

See here:

I have authored wordpress wordpress plugin very long time ago, however i visited Wordpress Codex and i believe that's possible:

<?php add_action( $tag, $function_to_add, $priority, $accepted_args ); ?> 

I believe you need to pass them being an array. Look under good examples "take arguments".


Rather than:


it ought to be:


...where 2 is the amount of arguments and 10 may be the priority where the function is going to be performed. You do not list your arguments in add_action. This initially tripped me up. Your function then appears like this:

function function_name ( $arg1, $arg2 ) { /* do stuff here */ }

Both add_action and performance use functions.php and also you specify your arguments within the template file (page.php for instance) with do_action like so:

do_action( 'name-of-action', $arg1, $arg2 );

Hope this can help.