Bird
0
0

Why does the following code not pass the second argument to my_function?

medium📝 Debug Q7 of 15
Wordpress - WordPress Hooks System
Why does the following code not pass the second argument to my_function?
add_action('save_post', 'my_function', 10, 1);
function my_function($post_id, $post) {
  // code
}
ABecause priority 10 prevents multiple arguments
BBecause <code>add_action</code> specifies only 1 accepted argument
CBecause the function name is incorrect
DBecause the hook <code>save_post</code> does not pass any arguments
Step-by-Step Solution
Solution:
  1. Step 1: Check accepted args parameter

    The code specifies 1 accepted argument, so WordPress passes only the first argument.
  2. Step 2: Confirm hook passes multiple arguments

    The save_post hook passes 2 arguments, but only one is accepted here.
  3. Final Answer:

    Because add_action specifies only 1 accepted argument -> Option B
  4. Quick Check:

    Accepted args limits arguments passed [OK]
Quick Trick: Accepted args controls how many hook arguments your function gets [OK]
Common Mistakes:
  • Assuming hook passes only one argument
  • Blaming priority for argument count
  • Incorrect function name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes