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

Attach upload to a post.


Description Description


Parameters Parameters

$post_ID

(int) (Required) Post ID.

$post_content

(string) (Required) Post Content for attachment.


Top ↑

Source Source

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 ) );
				}
			}
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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