- WP supports only function get a post is
get_post()
function, but it just get information of post when you knowpost_id
$post = get_post($post_id);
- If you want to get post without
post_id
, must to useget_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: