0

If i use wp_insert_post like that:

wp_insert_post(array('post_title' => 'some title', 'post_status' => 'draft', 'meta_input' => array( '_pf_mainphone' => $pro_phone ),'tax_input' => array( 'places_taxonomy' => $_POST["npf_newpro_places"], 'protags' => $_POST["npf_newpro_tags"],)));

And let's suppose that the _pf_mainphone isn't a real custom field (there isn't such a custom field in my installation / setup...).

The Question is will it write something to database or will it just ignore this part of the code?

The Reason i ask this (although i think it's not really necessary for answering the question) is:

I want to code a function that will that will take each field in a long form and set it's value to be the value of custom field with the same name as the field's name attribute, and there are 2 (out of 34) fields that don't exists as custom fields (i use another function for another purpose with them...).

1 Answer 1

0

Yes, wp_insert_post() will automatically insert new postmeta as well.

I just tried out your exact code and it worked. And the reason behind this could be quite simple: In WordPress, meta info for a post is only a key and value pair. There is no strict rule that keys have to be defined somewhere, so you can easily insert your own at any given moment.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.