Uses
Uses | Description |
---|---|
wp-includes/wp-db.php: wpdb::get_results() | Retrieves an entire SQL result set from the database (i.e., many rows). |
wp-includes/wp-db.php: wpdb::update() | Updates a row in the table. |
Attach upload to a post.
(int) (Required) Post ID.
(string) (Required) Post Content for attachment.
File: wp-includes/class-wp-xmlrpc-server.php
public function attach_uploads( $post_ID, $post_content ) { global $wpdb; // Find any unattached files. $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); if ( is_array( $attachments ) ) { foreach ( $attachments as $file ) { if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { $wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); } } } }
Version | Description |
---|---|
2.1.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/attach_uploads