Answer the question
In order to leave comments, you need to log in
How to remove / add a post in Wordpress and its metadata using SQL query?
Firework! I tried the standard api wp - it turned out very slowly (there are a lot of records). Help with requests. You need to:
1. delete a custom post hung with taxonomies and custom fields. As I understand it, there are some tails and metadata that need to be removed.
2. add a custom post with taxonomies and custom fields.
Answer the question
In order to leave comments, you need to log in
In general, thanks to all the local gours, I did it myself. Adding / updating 1500 posts with all sorts of checks using the wp api (wp_insert_post / wp_update_post) - took about 10 minutes. Through $wpdb->query - about a second. Might be useful to someone:
//создаем уникальный индекс вместо обычного
$wpdb->query('ALTER TABLE wp_posts DROP INDEX post_name');
$wpdb->query('ALTER TABLE wp_posts ADD UNIQUE post_name (post_name)');
$q ="INSERT INTO wp_posts SET post_parent = 0, post_type = 'mytype', post_author = 1, post_content ='".$content_field."', post_title='".$content_title."', post_name= '".$content_name."' ON DUPLICATE KEY UPDATE post_name= '".$content_name."', post_content = '".$content_field."', post_title='".$content_title."'";
$wpdb->query($q);
$post_id = $wpdb->get_var("SELECT ID FROM wp_posts wp WHERE post_name = '".$content_name."'");
//Возвращаем обычный индекс
$wpdb->query('ALTER TABLE wp_posts DROP INDEX post_name');
$wpdb->query('ALTER TABLE wp_posts ADD INDEX post_name (post_name)');
And why do you need these complex queries, make a simple Ajax interface and call deletion-adding by native methods one at a time, and not all at once.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question