Created
February 17, 2018 13:13
-
-
Save westcoastdigital/69f04f6d8e57e8bdf783e445bceb0633 to your computer and use it in GitHub Desktop.
use function to detect if slug exists in WP databas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Use the function if ( the_slug_exists( '404' ) ) {} to detect if is in database | |
| */ | |
| function the_slug_exists($post_name) | |
| { | |
| global $wpdb; | |
| if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')) { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment