I have custom post types for videos on my site. They are displayed on the pages in the form of cards. One post is a picture, a title for a video card, and a link. When you click on the card, a popup with a video should open. I display video cards using the WP_Query loop. My problem is that I don’t know how to link to the video. The post does not have a single page. I need to somehow specify a link to it when creating a post and display it. How can i do this?
<?php $video_link = get_field('video_link'); ?>
<?php
$case = new WP_Query( array(
'post_type' => 'videos',
'paged' => -1,
'order' => 'DESC',
) );
while ( $case->have_posts() ) : $case->the_post(); ?>
<?php $cur_terms = get_the_terms( $case->post->ID, 'categories' ); ?>
<li class="portfolio-section__item __js_masonry-item>
<a class="project-preview project-preview--elastic" data-fancybox href="<?php echo $video_link ?>">
<span class="project-preview__image">
<img src="<? the_post_thumbnail_url() ?>" alt="<?php the_title(); ?>">
<span class="hover-button">
<svg width="17" height="19">
<use xlink:href="#triangle"></use>
</svg>
</span>
</span>
<span class="project-preview__bottom">
<span class="project-preview__title"><?php the_title(); ?></span>
<span class="project-preview__icon">
<svg width="24" height="23">
<use xlink:href="#link-arrow2"></use>
</svg>
</span>
</span>
</a>
</li>
<?php endwhile;
$case->reset_postdata(); ?>
2
Answers
I would probably simply add the link in the content of the custom post type, from what I see you are not using it. Or you could also add it as an excerpt.
Or like Cornel said, use the built in custom fields. More info here wordpress.org/support/article/custom-fields
Last solution is to use ACF plugin (Advanced Custom Fields) and just create a custom field for the link of the video.
Hope this helps
The built-in custom fields method would be the quickest and simplest, but not the most elegant.
Here is a more elegant method of adding a custom metabox and a field.
Then to get the value for use in your template, just call like this:
Source Docs: