On this page
wp_xmlrpc_server::attach_uploads( int $post_ID, string $post_content )
Attach upload to a post.
Parameters
$post_IDint Required-
Post ID.
$post_contentstring Required-
Post Content for attachment.
Source
File: wp-includes/class-wp-xmlrpc-server.php. View all references
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 ) );
}
}
}
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::update() wp-includes/class-wpdb.php | Updates a row in the table. |
| wpdb::get_results() wp-includes/class-wpdb.php | Retrieves an entire SQL result set from the database (i.e., many rows). |
Used By
| Used By | Description |
|---|---|
| wp_xmlrpc_server::mw_editPost() wp-includes/class-wp-xmlrpc-server.php | Edit a post. |
| wp_xmlrpc_server::blogger_newPost() wp-includes/class-wp-xmlrpc-server.php | Creates new post. |
| wp_xmlrpc_server::blogger_editPost() wp-includes/class-wp-xmlrpc-server.php | Edit a post. |
| wp_xmlrpc_server::mw_newPost() wp-includes/class-wp-xmlrpc-server.php | Create a new post. |
| wp_xmlrpc_server::_insert_post() wp-includes/class-wp-xmlrpc-server.php | Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/attach_uploads