Guest User

Untitled

a guest
Jun 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. <?php
  2. /**
  3. * Returns max ID of the source wp_posts table.
  4. *
  5. * @return int
  6. */
  7. public function get_source_max_article_id() {
  8.  
  9. $in_source_post_statuses = [ 'publish', 'draft', 'pending', 'private', 'trash', 'inherit' ];
  10. $post_status_placeholders = implode( ', ', array_fill( 0, count( $in_source_post_statuses ), '%s' ) );
  11. $prepare_values = array_merge( [ $this->post_type ], $in_source_post_statuses );
  12.  
  13. $source_db = self::$source_db_handle;
  14. $sql = $source_db->prepare(
  15. "SELECT max(ID) FROM {$source_db->prefix}posts
  16. WHERE post_type=%s AND post_status IN ( {$post_status_placeholders} )",
  17. $prepare_values
  18. );
  19.  
  20. return (int) $source_db->get_var( $sql );
  21. }
Add Comment
Please, Sign In to add comment