Archived topic
PHP code in hooks doesn't work the same way that in the php theme files
3 replies · Started by Lucas on August 10, 2018
Hello
First of all I want to say that I'm a programming amateur, and my knowledge of php is very very limited, and all has been learnt by trial an error!
I want to display some oEmbed media in my portfolio page. For that I have created two new php files in my theme. For that I've used Pods to add an oEmbed field in each of my portfolio items. Then I've created two new php files in the theme, in which I've changed the "content" for "projcontent"
do_action( 'generate_after_entry_header' );
$embeded_media = get_post_meta($post->ID, 'embeded_media', true);
if ( generate_show_excerpt() ) : ?>
<div class="entry-summary" itemprop="text">
<?php
echo '<div class="embeded_media embeded_media_archive">';
echo $embeded_media;
echo '</div>';
the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else :
if($embeded_media != '') {
echo '<div class="embeded_media embeded_media_archive">';
echo $embeded_media;
echo '</div>';
}
?>
<div class="entry-content" itemprop="text">
This way I was able to embed the media. But since I now have GP Premium with Hooks, I wanted to do it that way. However, when I paste in the appropriate hook the code:
$embeded_media = get_post_meta($post->ID, 'embeded_media', true);
<?php
echo '<div class="embeded_media embeded_media_archive">';
echo $embeded_media;
echo '</div>';
?>
it just doesn't work. Nothing happens.
Am I missing something here? Doesn't GP have access to the Pods fields?
Thanks!
What's the exact code you're adding into Hooks?
If it's the above, it should look like this:
<?php
$embeded_media = get_post_meta(get_the_ID(), 'embeded_media', true);
echo '<div class="embeded_media embeded_media_archive">';
echo $embeded_media;
echo '</div>';
?>
It works!
I think I tried it so many times that I've messed around the code.
Thank you!
You're welcome :)