0

I'm trying to access custom meta data from a custom post type called 'Videos'

The following code is on a template page called 'single-videos.php'

A custom field called 'Video URL', 'Video Width' and 'Video Height'

However when i run the script, these don't return the values for that particular post.

Any ideas where I might be going wrong?

<?php
/**

*Template Name: Individual Video



*/
get_header('inner');
?>




<section class="section2 portfolio">
      <div class="container">

          <h1 class="title-nml-individual-post text-center gal-title">
    <?php
echo get_the_title($post_id);
?>
   </h1>
        <div class="row" style="padding-left: 50px; padding-right: 50px; padding-top: 39px;">

// *** THESE TWO SECTIONS I WAS JUST EXPERIMENTING BUT STILL 
HAD NO LUCK GETTING THE VALUES I NEEDED

<?php
get_post_meta(get_the_ID());
?>

<?php
the_meta($video->ID, 'video_url', true);
?>

<iframe class="wistia_embed" src="" name="wistia_embed" width="<?php
the_meta($video->ID, 'video_width', true);
?>" height="<?php
the_meta($video->ID, 'video_height', true);
?>" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" webkitallowfullscreen="webkitallowfullscreen" oallowfullscreen="oallowfullscreen" msallowfullscreen="msallowfullscreen"></iframe>

        <img class="post-feature-image" src=" <?php
the_post_thumbnail_url('full');
?> "></img>
          </div> <!--end row -->
        </div> <!-- end container-->
    </section>      


<?php
include_once('include/form.php');
?>
<?php
get_footer('inner');
?>

Screenshot of WP Admin

Please let me know if there is anything else i need to provide in the way of details.

  • Where did you place the above code? – bravokeyl Jun 9 '16 at 9:21
  • Can you please post the whole code, including the loop and how you register the custom meta fields? – Boris Kuzmanov Jun 9 '16 at 9:22
  • @BorisKuzmanov please see above – Brendan Gooden Jun 9 '16 at 11:15
1

I don't know why you are using a custom template for displaying an individual Video post when there is a single file that is used for this purpose - single-{post_type}.

https://codex.wordpress.org/Post_Type_Templates

Using the single file, you will be able to get the post ID with $post->ID or get_the_ID().

if( have_posts() ) : while( have_posts() ) : the_post();
echo get_post_meta( $post->ID, 'video_url', true );
// you can display all post's information within this loop
endwhile; endif;

You can find more about the WordPress Template Hierarchy here.

WordPress Template Hierarchy.

  • Correct, that's why I'm using 'single-videos.php' as my template file. I made the mistake of using variables $videos instead of $post. Thanks! – Brendan Gooden Jun 9 '16 at 12:01
0

Were you showing all of your Custom Post Type "Video" post on a loop?

Im not sure if your $video->ID matches with your CPT post id.

Try Using get_the_ID() in place of $video->ID for reference: https://developer.wordpress.org/reference/functions/get_the_id/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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