Plugin Author
Brecht
(@brechtvds)
Hi there,
You could check how it’s done in the /custom-related-posts/helpers/output.php file. It uses the sortByOrder
function to sort the relations by their “order” key.
Something like this should work:
usort( $custom_relations, function( $a, $b ) { return $a['order'] - $b['order']; } );
Thread Starter
ririro
(@ririro)
Thanks a lot for your reply. That was helpful! Fixed it. In case it’s relevant for others or you find it fun to see:
$current_post_id = get_the_ID();
$custom_relations = CustomRelatedPosts::get()->relations_to($current_post_id);
$custom_relation_ids = array_keys($custom_relations);
// Loop argumnetsnts show posts by category
$args = array(
'post__in' => $custom_relation_ids,
'post__not_in' => array( $post->ID ),
'orderby' => 'post__in' <-- added this
+ a bit lower in the code
remove_all_filters('posts_orderby'); // ADDED
Got it to work. Again thanks!