I am learning meta boxes in Wordpress theme development. In a tutorial I watched, tutor wrote a function for saving meta box values. As an argument he add $post_id and $post.
I know $post is a global variable but what about $post_id, I wonder where is it coming from.
A little bit of research i did before asking here, I found this: https://wordpress.stackexchange.com/a/299134/172202
One of the answers in the link, It says:
Another way you might get a post ID is in a hook callback. For example, in the post_thumbnail_size hook the callback receives a post ID as the 2nd argument
And gives this example
function wpse_299132_post_thumbnail_size( $size, $post_id ) { return $size; } add_filter( 'wpse_299132_post_thumbnail_size', 'wpse_299132_post_thumbnail_size', 10, 2 );
The Question I Have
In the filter hook I know 10 is priority and 2 is number of arguments as this question's anwers says:
Which hook callback has priority if both plugin and theme use the same hook?
But since that 2 parameter is the number of arguments, it is not the n th argument, because the id parameter inserted as the second parameter, I first thought it is the n th parameter but with the question's answer above, i found out that it is actually number of arguments. I thought if you name the parameter as $post_id, the hook automatically adds the post id value, but that's not the case?
And first question link's answer also says this:
But that's just the name used in the documentation to make it clear what the variable contains. You can call it anything you like. This is also valid, for example:
function wpse_299132_post_thumbnail_size( $size, $myPostId ) { return $size; } add_filter( 'wpse_299132_post_thumbnail_size', 'wpse_299132_post_thumbnail_size', 10, 2 );
$myPostId is the 2nd argument, so will contain a post ID. But what you call it doesn't matter.
If 2 in the hook parameter would be n th argument, if we would add $myPostId as the first parameter, it wouldn't work, but it is actually number of arguments.
How the hooks know if it should give post id value to the parameter?