So I have two post types. Which are in relation via post object. In a single CPT, I am showing relational posts from CPT 2. Works fine. But I want to order those posts per the ACF date field.
If I do, the normal loop it shows fine with the order, but if I put a relation thing, which is needed to pull posts via object it’s not working. Can’t figure how to do this. Any ideas?
<?php
// query events
$events = new WP_Query(array(
‘post_type’ => ‘company’,
‘post_status’ => ‘publish’,
‘posts_per_page’ => -1,
‘meta_key’ => ‘webinar_date’,
‘orderby’ => ‘meta_value’,
‘order’ => ‘DESC’,
)
);
?>
<?php if ( $events->have_posts() ) : ?>
<?php while ( $events->have_posts() ) : $events->the_post(); ?>
<?php
$featured_posts = get_field(‘relation’);
if( $featured_posts ): ?>
<?php foreach( $featured_posts as $post ):
// Setup this post for WP functions (variable must be named $post).
setup_postdata($post); ?>
<?php the_title(); ?>
<?php endforeach; ?>
<?php
// Reset the global post object so that the rest of the page works correctly.
wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; // end of the loop. ?>
<?php endif;?>