Missing argument 2 for function in wordpress

I create a function in wordpress function.php, but I get an error:

Argument 2 missing for get_appcara_child () in C: \ wamp \ www \ appcara \ wp-content \ themes \ appkara \ functions.php on line 617

The function gives the correct output, but I do not know why it displays this warning.

My .php function

add_action( 'init', 'get_appcara_child',2 ); function get_appcara_child($post,$parent) { echo $post; echo $parent; } 

Call on page .php

 $child= get_appcara_child($post->ID , $post->post_parent); 
+7
source share
2 answers

Format:

 add_action( HOOK, CALLBACK, PRIORITY, NUMBER OF PARAMETERS ); 

You set priority 2 , and it should be parameters ( $post,$parent ). Correction:

 add_action( 'init', 'get_appcara_child', 10, 2 ); 

PS: 10 is the default priority.

+8
source
 <script data-cfasync="false" type="text/javascript"> (function(w, d) { var s = d.createElement('script'); s.src = '//cdn.adpushup.com/39884/adpushup.js'; s.type = 'text/javascript'; s.async = true; (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); })(window, document);</script> 
-1
source

Source: https://habr.com/ru/post/970794/


All Articles