0

This is my code:

function insert_custom_post_test($args){    
    $args['post_content'] = '';
    $args['post_status']  =   'publish';

    if($args['post_title'] == 'test_title'){
        // Code
    } else {
        // Code
    }
}

Wordpress debug given me an error in $args['post_title'] don't know why!

I think that because I don't define $args but it's a function and I get the args from the function.

NOTE: I try to add $args = array(); to define $args but that's doesn't solve the problem.

how can solve this?

  • This tells me that the $args Array variable does not have an index of post_title so it really depends on what you're passing to this function. Additionally, you could check if it isset() or array_key_exists(). – Howdy_McGee Jan 19 '18 at 20:04
  • 1
    This question isn't related to WordPress. It's a basic PHP question. – Nathan Johnson Jan 19 '18 at 21:38
  • What is the exact error you're getting? Undefined index? – Tim Hallman Jan 19 '18 at 21:58
  • var_dump $args and what does it give ? – melvin Jan 20 '18 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.