WP_Importer::get_imported_posts() WordPress Method

The WP_Importer::get_imported_posts() method returns an array of posts that have been imported.

WP_Importer::get_imported_posts( string $importer_name, string $blog_id ) #

Returns array with imported permalinks from WordPress database


Parameters

$importer_name

(string)(Required)

$blog_id

(string)(Required)


Top ↑

Return

(array)


Top ↑

Source

File: wp-admin/includes/class-wp-importer.php

	public function get_imported_posts( $importer_name, $blog_id ) {
		global $wpdb;

		$hashtable = array();

		$limit  = 100;
		$offset = 0;

		// Grab all posts in chunks.
		do {
			$meta_key = $importer_name . '_' . $blog_id . '_permalink';
			$sql      = $wpdb->prepare( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = %s LIMIT %d,%d", $meta_key, $offset, $limit );
			$results  = $wpdb->get_results( $sql );

			// Increment offset.
			$offset = ( $limit + $offset );

			if ( ! empty( $results ) ) {
				foreach ( $results as $r ) {
					// Set permalinks into array.
					$hashtable[ $r->meta_value ] = (int) $r->post_id;
				}
			}
		} while ( count( $results ) == $limit );

		return $hashtable;
	}

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.