i have a problem with get_post_meta. Normally it works, but with this query for same reason it doesn't.
So I have 12 custom post called official matters, which are creating tabs with accordion on home page. With the post meta I want to create an if statement to check if the tab will be a link or an outgoing link or a tab.
The problem is that the get_post_meta is passing only info from one post. So after var_dump I got only array(1) { ["link"]=> string(0) ""}
Could you please tell me where is the reason?
<div id="collapse-official-matters" class="col-xl-12">
<div class="official-matters-group">
<?php $args = array('post_type' => 'official-matters', 'showposts' => 20, 'orderby' => 'date', 'order' => 'ASC',); $the_query = new WP_Query( $args ); ?>
<?php $i = 0; $row = 0;
while ( $the_query->have_posts()) {
$the_query->the_post();
if ($i === 4) {
$i = 0;
$row++;
}
$meta = get_post_meta( $post->ID, 'official_matters_details', true );
$postsData[$row]['tabs'][$i] = [
'id' => get_the_id(),
'thumbnail' => get_the_post_thumbnail_url(),
'title' => get_the_title()
];
$postsData[$row]['content'][$i] = [
'id' => get_the_id(),
'excerpt' => get_the_excerpt()
];
$i++;
}
?>
<div id="accordion">
<?php foreach($postsData as $key => $value) :
$tabs = $value['tabs'];
$contents = $value['content'];
?>
<div class="customRow">
<?php foreach($tabs as $key => $value) : ?>
<div class="info-tab col-xl-3">
<div class="info-img">
<img src="<?php echo $value['thumbnail'] ?>" />
</div><!-- .news_img -->
<?php if ($meta['isLink'] === '1') {
if ($meta['outgoingLink'] === '0') { ?>
<a href="<?php echo $meta['link'] ?>" class="info-title collapsed" role="button">
<?php echo $value['title'] ?>
</a><!-- .info-title -->
<?php } else { ?>
<a href="<?php echo $meta['link'] ?>" class="info-title collapsed" role="button" target="_blank">
<?php echo $value['title'] ?>
</a><!-- .info-title -->
<?php } ?>
<?php } else { ?>
<a data-toggle="collapse" data-target="#collapse-<?php echo $value['id'] ?>" href="#collapse-<?php echo $value['id'] ?>" class="info-title collapsed" role="button" aria-expanded="false" aria-controls="collapse-<?php echo $value['id'] ?>">
<?php echo $value['title'] ?>
</a><!-- .info-title -->
<?php } ?>
</div><!-- .info-tab -->
<?php endforeach; ?>
<?php foreach($contents as $key => $value) : ?>
<div class="official-matters-content">
<div class="info-tab-content collapse" id="collapse-<?php echo $value['id']; ?>" data-parent="#accordion">
<div class="card card-body">
<?php echo $value['excerpt'] ?>
</div><!-- .card -->
</div><!-- .info-tab-content -->
</div><!-- .official-matters-content -->
<?php endforeach; ?>
</div>
<?php endforeach ;?>
</div>
<?php wp_reset_postdata(); ?>
<?php if (false) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="info-tab col-xl-3">
<div class="info-img">
<?php the_post_thumbnail(); ?>
</div><!-- .news_img -->
<a data-toggle="collapse" href="#collapse-<?php the_ID(); ?>" class="info-title" role="button" aria-expanded="false" aria-controls="collapse-<?php the_ID(); ?>">
<?php the_title(); ?>
</a><!-- .info-title -->
</div><!-- .info-tab -->
<div class="official-matters-content">
<div class="info-tab-content collapse" id="collapse-<?php the_ID(); ?>">
<div class="card card-body">
<?php the_excerpt(); ?>
</div><!-- .card -->
</div><!-- .info-tab-content -->
</div><!-- .official-matters-content -->
<?php
endwhile;
wp_reset_postdata();
?>