retesere20

Untitled

Apr 16th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. public function post_exists( $post_name, $post_type='post' ) {
  2. global $wpdb;
  3.  
  4. $query = "SELECT ID FROM $wpdb->posts WHERE 1=1";
  5. $args = array();
  6.  
  7. if ( !empty ( $post_name ) ) {
  8. $query .= " AND post_name LIKE '%s' ";
  9. $args[] = $post_name;
  10. }
  11. if ( !empty ( $post_type ) ) {
  12. $query .= " AND post_type = '%s' ";
  13. $args[] = $post_type;
  14. }
  15.  
  16. if ( !empty ( $args ) )
  17. return $wpdb->get_var( $wpdb->prepare($query, $args) );
  18.  
  19. return true;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment