Support » Plugins » passing a variable from Post to Functions.php

  • I have spent the last few days trying to implement some nice WP customization, in order to display thumbnail images grabbed from various posts.

    What I try to achieve: I want to display a series of thumbnails of related posts, in the sidebar of my blog. I am trying to adapt a smart little script found at… and the only thing that does not work is: passing the post ID to the script (in the functions.php).

    I am using this code – located in my sidebar.php – to get the IDs of two random posts from the same category:

    <?php $postslist = get_posts('category_name=portfolio&numberposts=2&orderby=rand');
    foreach ($postslist as $post) :
    setup_postdata($post);  ?>
    <?php the_ID(); ?>
    <?php $trueID = the_ID();
    echo $trueID; //this works!!
    bdw_get_images($trueID); //does not work ?>
    <?php endforeach; ?>

    This piece of code is echoing the ID’s correctly, so this is working. What does not work, is sending the $trueID variable to my functions.php. The function starts like that:

    function bdw_get_images($postId){
    $iPostID = $postId

    but this $postId has no effect whatsoever. The result of the function is that is displays the latest thumbnail image, but it doesn’t get the post ID.

    Obviously I’m doing something wrong, but I haven’t found any clear description about how to pass this variable to my function. Here is a preview page of my blog, so you can see what I’m trying to do …

Viewing 1 replies (of 1 total)
  • Ha, writing this message obviously had a therapeutic effect !!

    I realize that the following does work:

    I wrongly assumed that this would give me the current post page, but no, since we’re outside of the main Loop, it passes exactly the ID I want….


Viewing 1 replies (of 1 total)
  • The topic ‘passing a variable from Post to Functions.php’ is closed to new replies.