'While Loop and Foreach Loop Wordpress
<?php
$args = array(
'post_type' => 'series',
'posts_per_page' => 100,
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_type' => 'DATE',
'meta_key' => 'release_date'
);
$series = new WP_Query($args);
?>
<?php while ($series->have_posts()) : $series->the_post(); ?>
<div class="star-list-details">
<div class="poster"><a href="<?php echo get_page_link($post->ID);?>"> <img src="<?php echo get_the_post_thumbnail_url($post->ID, 'thumbnail');?>"></a></div>
<div class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </div>
<div class="year"> <b><?php the_field('release_date');?></b> </div>
<div class="episodes"><?php the_field('episodes');?></div>
<div class="role"> <?php get_template_part('inc/movie','series-role'); ?></div>
</div>
<?php endwhile; ?>
<?php $series = get_field('series'); ?>
<?php foreach($series as $series):?>
<a href="<?php echo get_page_link($series->ID);?>"> <img src="<?php echo get_the_post_thumbnail_url($series->ID, 'thumbnail');?>"></a>
<a href="<?php echo get_page_link($series->ID);?>"><h3><?php echo $series->post_title;?></h3></a>
<?php the_field( 'series-movies-details', $series->ID );?>
<?php endforeach;?>
im trying to merge those two code but no luck please help. i want to get the post of ACF relationship field by order of DESC in my custom post type..............................................................................................................................................
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|