[Resolved] PHP code in hooks doesn't work the same way that in the php theme files

Home Forums Support PHP code in hooks doesn't work the same way that in the php theme files

This topic contains 3 replies, has 2 voices, and was last updated by  Tom 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #645150

    Lucas

    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!

    GeneratePress 2.1.3
    GP Premium 1.6.2
    #645362

    Tom Lead Developer

    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>';
    ?>
    #645543

    Lucas

    It works!
    I think I tried it so many times that I’ve messed around the code.
    Thank you!

    #645789

    Tom Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.