Skip to content

Instantly share code, notes, and snippets.

@ryanburnette
Created April 16, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanburnette/a7bb4e5f6e5fcae5078e055c48d92c25 to your computer and use it in GitHub Desktop.
Save ryanburnette/a7bb4e5f6e5fcae5078e055c48d92c25 to your computer and use it in GitHub Desktop.
<?php
function get_post_by_slug($slug) {
$args = array(
'name' => $slug,
'post_type' => 'page',
'post_status' => 'publish',
'posts_per_page' => 1,
);
$found_posts = get_posts($args);
if ( count($found_posts) > 0 ) {
return $found_posts[0];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment