WordPress query single post by slug
Asked 07 September, 2021
Viewed 1.5K times
  • 58
Votes

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

<?php
$post_id = 54;
$queried_post = get_post($post_id);
echo $queried_post->post_title; ?>

The problem is that when I move the site, the id's usually change. Is there a way to query this post by slug?

4 Answer