9

I am creating a function in wordpress function.php, but I am getting an error:

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

The function is giving the correct output, but I don't know why it is displaying this warning

My function.php is

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

    echo $parent;
}

Calling at page.php

$child= get_appcara_child($post->ID , $post->post_parent);
3
  • is $post->post_parent always set? Commented Jun 13, 2014 at 5:19
  • By using add_action() does Wordpress not call the function at some point (probably at initialization)? If so, are you sure Wordpress gives it two arguments? If not then you should look into that. Have you read the documentation thoroughly? Commented Jun 13, 2014 at 5:20
  • issue resolved . i have removed the add_action( 'init', 'get_appcara_child',2 ); Commented Jun 13, 2014 at 5:26

2 Answers 2

10

The format is:

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

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

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

PS: 10 is the default priority.

Sign up to request clarification or add additional context in comments.

Comments

-2
<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 Comment

Could you please add some explanation to your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.