0

I am trying to use this code in my WordPress site

<?php

    if(get_post_format() == 'video'){   

        function insert_game(){
            get_template_part( 'content', 'video-top' );    
        }

        add_action( 'colormag_after_header', 'insert_game' );
    }
 ?>


<?php get_header(); ?>

and in content-video-top.php is this code

echo get_post_meta( $post->ID, 'video', true );

The problem is that it doesn't show the custom fields, but after get_header() it works.

1 Answer 1

0

It seems that at that point, $post is not yet defined, you can make sure by turning debugging on.

Then add this before your get_post_meta( $post...:

global $post;

Or you can replace $post->ID with get_the_ID().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.