Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Last active December 24, 2015 08:17
Show Gist options
  • Save khoand0000/f0f2864412920d69466b to your computer and use it in GitHub Desktop.
Save khoand0000/f0f2864412920d69466b to your computer and use it in GitHub Desktop.
  • WP supports only function get a post is get_post() function, but it just get information of post when you know post_id
$post = get_post($post_id);
  • If you want to get post without post_id, must to use get_posts() function
$args = array(
  'posts_per_page' => 1, // required
   // ... your conditions, ex: 'post_type' => 'post', 'post_author' => 1
);
$posts = get_posts($args);
$post = null;
if ($posts)
  $post = $posts[0];

Ref:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment