WP_Importer::get_imported_posts()
Returns array with imported permalinks from WordPress database.
Method of the class: WP_Importer{}
No Hooks.
Return
Array
.
Usage
$WP_Importer = new WP_Importer(); $WP_Importer->get_imported_posts( $importer_name, $blog_id );
- $importer_name(string) (required)
- -
- $blog_id(string) (required)
- -
Notes
- Global. wpdb. $wpdb WordPress database abstraction object.
WP_Importer::get_imported_posts() WP Importer::get imported posts code WP 6.6.2
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; }