简体   繁体   中英

Create a post with custom taxonomy and custom field using raw MySQL query

I need to insert multiple posts using just raw MySQL with the following:

  1. Check if post duplicated by post_name field or not and IGNORE inserting if so.

  2. I need to insert a custom taxonomy called newspaper for the post.

  3. Create custom fields with the new post I already registered and I have the keys fifu_image_url , fifu_image_alt , and _cmb_link

I'm not SQL expert so I just did the basic query like so:

INSERT INTO `ctapp_posts`(`ID`, `post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`)
VALUES ?

This won't throw errors, and won't insert if duplicate.

  1. INSERT IGNORE INTO wp_posts (post_name)-> VALUES('. $postName. ')

  2. A bit more tricky. But you can read about the relations here: https://codex.wordpress.org/WordPress_Taxonomy

  3. You can log into the database and create new columns in wp_posts. Just set them to default null . This won't disturb the rest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM