• Hello,

    I want to pass a custom field value of the post to the iframe.
    I am adding iframe in each post, I want php code in iframe read the value for its parent post.

    The following will explain more:
    code in “wordpress/wp-content/themes/twentyone/single.php”:
    <iframe src="wordpress/wp-content/themes/twentyone/pop.php" width="280" height="280"></iframe><br />
    code in “wordpress/wp-content/themes/twentyone/pop.php”:

    <?php if ( get_post_meta($post->ID, 'mykey', true) ) : ?>
            <?php echo get_post_meta($post->ID, 'mykey', true) ?>
    <?php endif; ?>

    the message that the iframe show is:
    Fatal error: Call to undefined function get_post_meta() in C:\xampp\htdocs\wordpress\wp-content\themes\twentyone\pop.php on line 1

    I am sure there is something wrong, hope you understood what I mean, great appreciation for helpers ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • So two brains are better than one, and I could have never gotten to the solution without your function above (have no friggin’ idea WHY <?php get_post_meta($post->ID, 'mykey', true) ?> alone won’t do, which I was using…anyhow…)

    You have to pass the id parameter in the iframe URL.
    So change your iframe url call adding postid=<?php echo the_ID(); ?> it should be something like

    <iframe src="wordpress/wp-content/themes/twentyone/pop.php?postid=<?php echo the_ID(); ?>" width="280" height="280"></iframe><br />

    Then retrieve it in the iframe code using GET

    query_posts('p='.$_GET['postid']);

    So the whole iframe code will be:

    <?php query_posts('p='.$_GET['postid']); ?><?php if ( get_post_meta($postid, 'yourkey', true) ) : ?><?php echo get_post_meta($postid, 'yourkey', true) ?><?php endif; ?>

    Also, if you are getting the error above, it might be that you have to create a template for the iframe code, then assign it to a new page. Be sure to include all the working templates tags like WP_head and so on.

    Hope it helped!

    I can’t make this work. I’m getting the following error:

    Fatal error: Call to undefined function get_header() in D:\xampplite\htdocs\*****\wp-content\themes\*****\iframe.php on line 1

    could you please send me the whole single.php and pop.php (iframe.php in my case) code?

    @mbtocalli

    I just had to implement it on another theme, and since that function on the new theme (and WP 3.1) did not work I had to change it to this

    <?php $pid=$_GET["pid"]; query_posts('p=' . $pid); ?><?php if ( get_post_meta($pid, 'Author Email', true) ) : ?><?php echo get_post_meta($pid, 'Author Email', true) ?><?php endif; ?>

    Use this function above to get whatever custom value for a specific key you are using (in my case the key is Author Email).

    The call from the single.php file does not change.
    I think you are messing things up setting everything in the same file.

    What goes in the single.php is just this

    <iframe src="wordpress/wp-content/themes/twentyone/pop.php?postid=<?php echo the_ID(); ?>" width="280" height="280"></iframe>

    Whereas the piece of code above goes in your iframe code, where you want the custom value to be displayed. Hope it is clearer now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pass custom field value from post to iframe’ is closed to new replies.