What is the best way of retrieving a specific post in Wordpress?
Posted
by Steven
on Stack Overflow
See other posts from Stack Overflow
or by Steven
Published on 2010-04-08T18:43:32Z
Indexed on
2010/04/08
18:53 UTC
Read the original article
Hit count: 230
I need to retrieve a specific post to display on my websites front page. To avoid hard coding the post ID, I've added a custom property where I add the post ID.
The following code displays the wanted post:
(The code is within the LOOP)
// Get content from specific post (in this case, Åpningstider post))
$openingHoursID = get_post_meta($post->ID, "apningstider", true);
if (!empty($openingHoursID))
{
$openingHoursPost = get_post($openingHoursID);
$openingHours = $openingHoursPost->post_content;
}
else
$openingHours = "Åpningstid ikke angitt";
<div class="openinghours"><?php echo $openingHours; ?></div>
- Is there a better / easier way?
- The output is striped for HTML. How can I maintain HTML?
© Stack Overflow or respective owner