wp_xmlrpc_server::attach_uploads( int $post_id, string $post_content )

Attaches an upload to a post.


Parameters

$post_id int Required
Post ID.
$post_content string Required
Post Content for attachment.

Top ↑

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 ) && str_contains( $post_content, $file->guid ) ) {
				$wpdb->update( $wpdb->posts, array( 'post_parent' => $post_id ), array( 'ID' => $file->ID ) );
			}
		}
	}
}


Top ↑

Changelog

Changelog
Version Description
2.1.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.