jeudi 22 octobre 2015

Echo Post ID from Post Slug or Post Title

I try to get a post ID based on the post tile or slug (doesn't matter to me which one). After that I want to add the ID to a shortcode.

Working code

<?php 
    $test123 = get_post(30);
    echo $test123->ID; /* this works and returns 30 */
?>

<?php 
echo do_shortcode("[shortcode id='{$test123->ID}']"); /* this also works */
?>

So the next step is get the post ID based on slug or title. How do I do this? I tested different codes but nothing works till so far.

Many thanks for any help in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire