WordPress.org

Ready to get started?Download WordPress

Forums

Php function: $pageID from slug? (2 posts)

  1. fortyfoxes
    Member
    Posted 7 years ago #

    I am trying to get the postID from a postSlug. Thought I could use "query_posts" to do this. I don get what is happening as I get content in the pageArray, but putting the following code int the template fails to print anything for "about_PageID". I tried adding "setup_postdata", but no joy. Any ideas?

    <?php
    $pageArray = query_posts('pagename=about'); //retrieves the about page only
    setup_postdata($pageArray);
    $about_PageID = $pageArray->ID]
    echo "Page ID: " . $about_PageID;
    echo "<p></p>";
    print_r($pageArray);
    ?>

  2. Kafkaesqui

    Posted 7 years ago #

    $about_PageID = $pageArray[0]->ID;

    query_posts sort of creates an array of (object) arrays, so you have to pass the array key.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags