PHP Code Widget
Trying to access the $post-ID for a single page and not happening... (3 posts)

  1. sdickert
    Posted 5 years ago #

    Been trying for quite some time to get a simple one-liner to work on my site.


    Basic framework for the page template:

    <?php get_header(); ?>
    <?php include (TEMPLATEPATH . '/flash-sidebar.php'); ?>
    <?php get_footer(); ?>

    In the flash_sidebar, I have three widgets and each are doing the same function:

    <?php $key="FlashTech"; echo get_post_meta($post->ID, $key, true); ?>

    Looks easy, right? The sidebar is not running inside the loop which created the page, and I have been scouring how to make the $post-ID come up in the execphp widget. I could get the_meta() function to work in the widget (which I assume is because it runs outside TheLoop, but nothing else. I even tried some other ideas out there such as:

    <?php function tempfunct() {
    	global $post;
    	$thePostID = $post->ID;
    	echo $thePostID;
    } tempfunct(); ?>

    And the widget does not run. Any ideas why? Feedback very much appreciated.

  2. stvwlf
    Posted 5 years ago #

    I've made this work at times by setting a variable within the loop
    $post_id = $post->ID;

    then within the function

    <?php function tempfunct() {
    	global $post_id;
    	echo $post_id;
    } ?>
  3. sdickert
    Posted 5 years ago #

    Thank mate! That fixed it. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic