Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

WordPress query single post by slug

Asked by Edyth Ferrill Jul 5, 2021 1.8K views 1 answer
Share

About this question

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 changing. Is there a way in WordPress get post by slug?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.