日付で新しい順(DESC)にしたい場合
functions.php
/* 関連記事の調整 */
add_filter( 'acf/fields/relationship/query', 'custom_acf_relationship_query', 10, 3 );
function custom_acf_relationship_query( $args, $field, $post_id ) {
$args['orderby'] = 'post_date'; //投稿日付順
$args['order'] = 'DESC'; //新しい順
return $args;
}
今開いている投稿を除外する場合
functions.php
/* 関連記事の調整(開いている投稿を除外) */
add_filter( 'acf/fields/relationship/query', 'custom_acf_relationship_query', 10, 3 );
function custom_acf_relationship_query( $args, $field, $post_id ) {
$args['post__not_in'] = array( $post_id ); //今開いている投稿を除外
$args['orderby'] = 'post_date'; //投稿日付順
$args['order'] = 'DESC'; //新しい順
return $args;
}
参考
https://www.nxworld.net/wordpress/wp-acf-custom-relationship-query-exclude-post.html