WordPress query single post by slug

前端 未结 4 858
情书的邮戳
情书的邮戳 2020-12-25 09:24

For the moment when I want to show a single post without using a loop I use this:



        
4条回答
  •  没有蜡笔的小新
    2020-12-25 09:44

    From the WordPress Codex:

     $the_slug,
      'post_type'   => 'post',
      'post_status' => 'publish',
      'numberposts' => 1
    );
    $my_posts = get_posts($args);
    if( $my_posts ) :
      echo 'ID on the first post found ' . $my_posts[0]->ID;
    endif;
    ?>
    

    WordPress Codex Get Posts

提交回复
热议问题