Check if image exists before uploading with media_sideload_image()

I wonder if you’re looking for the core attachment_url_to_postid() function that uses: $sql = $wpdb->prepare( “SELECT post_id FROM $wpdb->postmeta WHERE meta_key = ‘_wp_attached_file’ AND meta_value = %s”, $path ); $post_id = $wpdb->get_var( $sql ); Note the extra meta key _wp_attached_file check compared to your current snippet. If you need to check if an image url … Read more

How to run this SQL query of wp_terms database

Per comments, you basically have it – just GROUP BY $wpdb->term_relationships.object_id instead; also to be pernickety, you’d use standard (INNER) JOINs rather than LEFT ones: SELECT $wpdb->term_relationships.object_id FROM $wpdb->term_relationships JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id JOIN $wpdb->terms ON $wpdb->terms.term_id = $wpdb->term_taxonomy.term_id WHERE name IN (394, 396, 988, 666) GROUP BY $wpdb->term_relationships.object_id ORDER BY $wpdb->term_relationships.term_taxonomy_id DESC

Massive Tags Remove Using MySQL

MySql DELETE syntax is not very different fiom SELECT, so you can delete from multiple tables using a single query. Taxonomies informations in WordPress are in 3 tables: wp_terms wp_term_taxonomy wp_term_relationships the first 2 contain term / taxonomy informations, the 3rd contains association between terms and posts. The query to delete all tags from WordPress … Read more