D
D
deleted-stiping2015-11-27 22:46:21
PHP
deleted-stiping, 2015-11-27 22:46:21

How to get the id of a video attached to a post in wordpress?

There is a cycle that displays my posts, videos are attached to these posts through the admin panel. I need to get the id of the attached file for each video. single.php code:

<?php get_header();?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php the_title('<div class="title-block">', '</div>'); ?>



<div class="block-text">
  <div>Автор:&nbsp;<?php the_author_meta('display_name'); ?></div>
  <div>Добавлено:&nbsp;<?php the_time( get_option( 'date_format' ) ); ?></div>
</div>

<div class="block-text">
  <div>Кол-во просмотров:&nbsp;<?php echo getPostViews(get_the_ID()); ?></div>
  <div>Категория:&nbsp;<?php the_category( ',&nbsp; ' ); ?></div>
</div>

<?php setPostViews(get_the_ID()); ?>
<?php endwhile; ?>

<?php get_footer();?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Syomka Gavrilenko, 2015-11-28
@deleted-stiping

get_attached_media( 'video', get_the_ID() )

W
webpixel, 2015-11-28
@webpixel

$attachments = get_attached_media( 'video', $post->ID );

foreach ($attachments as $attachment_id => $attachment) {
  $metaData = wp_get_attachment_metadata($attachment_id);
}

var_dump($metaData);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question