Skip to content

Instantly share code, notes, and snippets.

@OscarAbadFolgueira
Created November 27, 2017 20:31
Show Gist options
  • Save OscarAbadFolgueira/5c851df358516b4152827a6c79722e1e to your computer and use it in GitHub Desktop.
Save OscarAbadFolgueira/5c851df358516b4152827a6c79722e1e to your computer and use it in GitHub Desktop.
Function that checks all the WordPress Posts Slugs
<?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