I have updated my query as shown below. This now pulls the request posts correctly but I am still getting an error on the sortby date. Error shown is:
[orderby] => post_date [order] => DESC [error] => [m] => [p] => 0
I can’t seem to get the sortby to work no matter what i try. Any ideas what I am missing?
<?php
$offspring = $horse->offspring;
remove_all_filters('posts_orderby'); // ADDED
$args = array(
'post_type'=>'horse',
'post_status'=>'publish',
'post__in'=> $offspring,
'suppress_filters' => true,
'ignore_custom_sort' => true,
'orderby' => 'date',
'order' => 'DESC'
);
$off_query = new WP_Query( $args );
?>
<?php
foreach($offspring as $offspring_id){
while ( $off_query->have_posts()) {
$off_query->the_post();
if($post->ID == $offspring_id){
$post = get_post($offspring_id);
setup_postdata($post);
get_template_part('partials/post','excerpt-offspring');
}
}
}
wp_reset_postdata();
?>
I have confirmed that $off_query is returning the results in the correct order yet my foreach loop is still posting in order of ID and not by date. I’ve been working on this a while and can’t seem to pinpoint the issue.