wp_xmlrpc_server::attach_uploads()
Attaches an upload to a post.
Метод класса: wp_xmlrpc_server{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$wp_xmlrpc_server = new wp_xmlrpc_server(); $wp_xmlrpc_server->attach_uploads( $post_id, $post_content );
- $post_id(int) (обязательный)
- Post ID.
- $post_content(строка) (обязательный)
- Post Content for attachment.
Заметки
- Global. wpdb. $wpdb WordPress database abstraction object.
Список изменений
С версии 2.1.0 | Введена. |
Код wp_xmlrpc_server::attach_uploads() wp xmlrpc server::attach uploads WP 6.6.2
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 ) ); } } } }