true, ) ); unset( $types_unsafe['attachment'] ); // Make sure post type names are safe to use as an SQL value. $types = array(); foreach ( $types_unsafe as $type ) { array_push( $types, esc_sql( $type ) ); } // Convert escaped post types to a string for use in our SQL statement. $types = implode( "','", $types ); // Prepare an SQL statement to efficiently set the default labels. // Only set this on posts that don't already have an admin label. $sql = "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) "; $sql .= "SELECT ID, '_admin_content_label', post_title "; $sql .= "FROM {$wpdb->posts} p "; $sql .= "LEFT JOIN {$wpdb->postmeta} pm "; $sql .= "ON p.ID = pm.post_id AND meta_key = '_admin_content_label' "; $sql .= "WHERE pm.meta_key IS NULL AND p.post_type IN ('{$types}')"; // Set default content labels. $wpdb->query( $sql ); }