Created
November 27, 2017 20:31
-
-
Save OscarAbadFolgueira/5c851df358516b4152827a6c79722e1e to your computer and use it in GitHub Desktop.
Function that checks all the WordPress Posts Slugs
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 | |
// Function that checks all the posts slugs | |
function oaf_post_exists_by_slug( $post_slug ) { | |
$args_posts = array( | |
'post_type' => 'posts', | |
'post_status' => 'any', | |
'name' => $post_slug, | |
'posts_per_page' => 1, | |
); | |
$loop_posts = new WP_Query( $args_posts ); | |
if ( ! $loop_posts->have_posts() ) { | |
return false; | |
} else { | |
$loop_posts->the_post(); | |
return $loop_posts->post->ID; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment