shortcodes-contest.php
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
add_shortcode('contest-slider', 'contest_slider');
function contest_slider(){
$custom_args = array(
'post_type' => 'nf_sub',
'posts_per_page' => 3,
'paged' => 1,
'post_status' => 'any',
'order' => 'DESC',
'orderby' => 'rand',
// 'meta_query' => array(
// 'relation' => 'AND',
// array(
// 'key' => '_form_id',
// 'value' => '2',
// 'compare' => '=',
// ),
// ),
);
$custom_query = new \WP_Query($custom_args);
ob_start();
$uniqid = uniqid();
if ($custom_query->have_posts()): ?>
<div id="<?php echo esc_attr($uniqid); ?>" class="<?php echo esc_attr($className); ?> ">
<div class="content-item carousel-items <?php echo $size; ?>">
<div class='swiper-wrapper'>
<?php while ($custom_query->have_posts()): $custom_query->the_post(); ?>
<div class="swiper-slide">
<?php $image = get_post_meta(get_the_ID(), '_field_11', true );
$num = get_post_meta(get_the_ID(), '_seq_num', true );
$cap = get_post_meta(get_the_ID(), '_field_8', true );
?>
<img src="<?php echo $image[$num];?>" alt="<?php echo $cap;?>">
<div class="contest_cap"><?php echo $cap;?></div>
</div>
<?php endwhile; ?>
</div>
</div>
<div class="swiper-button-prev" data-id="<?= $uniqid ?>"></div>
<div class="swiper-button-next" data-id="<?= $uniqid ?>"></div>
</div>
<?php endif;
wp_reset_query();
$output = ob_get_clean();
return $output;
}