How would I be able to insert data into the post meta table? I know how querying and wpdb works but I have no idea how I can just insert it into the table.
I have these two fields I want to insert ID and Title where Title should become a new post in my Custom Post type Company and ID should be the Content of it. I unfortunately have no idea how to do this.
EDIT: I’m not sure if it HAS to be the post meta table but as long as a new Custom post type post appears.
Thanks in advance!
You do not need to use the
post_meta
here, as all the Information is available inposts
.To insert a new post, use
wp_insert_post( $post )
, and pass the arguments to your$post
-array. This function can return aWP_Error
-object for Error handling (if the second argument is set totrue
, returns 0 on error if false), and returns theID
of the inserted post.See the full list of arguments for
wp_insert_post()
on the Codex.You can execute any query as follows and check for success , Let me know if it works.
Praveen