LoginSignup
0
0

More than 3 years have passed since last update.

Wordpress 投稿画面で Advanced Custom Fields の関連記事をソートする

Last updated at Posted at 2019-05-29

日付で新しい順(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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0