| 1 | function post_exists($title, $content = '', $date = '', $status = 'publish') { |
|---|
| 2 | global $wpdb; |
|---|
| 3 | |
|---|
| 4 | $post_title = stripslashes( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); |
|---|
| 5 | $post_content = stripslashes( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); |
|---|
| 6 | $post_date = stripslashes( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); |
|---|
| 7 | $post_status = stripslashes( sanitize_post_field( 'post_status', $status, 0, 'db' ) ); |
|---|
| 8 | |
|---|
| 9 | $query = "SELECT ID FROM $wpdb->posts WHERE post_status=%s"; |
|---|
| 10 | $args = array(); |
|---|
| 11 | $args[] = $post_status; |
|---|
| 12 | if ( !empty ( $date ) ) { |
|---|
| 13 | $query .= ' AND post_date = %s'; |
|---|
| 14 | $args[] = $post_date; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | if ( !empty ( $title ) ) { |
|---|
| 18 | $query .= ' AND post_title = %s'; |
|---|
| 19 | $args[] = $post_title; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | if ( !empty ( $content ) ) { |
|---|
| 23 | $query .= 'AND post_content = %s'; |
|---|
| 24 | $args[] = $post_content; |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | if ( !empty ( $args ) ) |
|---|
| 28 | return $wpdb->get_var( $wpdb->prepare($query, $args) ); |
|---|
| 29 | |
|---|
| 30 | return 0; |
|---|
| 31 | |
|---|
| 32 | } |
|---|