最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Post Object field orderby (Advanced Custom Field)

programmeradmin3浏览0评论

I created a Post Object field type (see attached screenshot post-object-0.png)

How do I output the instructors in order by the selection choices made by the users (see attached screenshot post-object.png)

My query is as follow:

$instructors = get_sub_field( 'instructors');
//var_dump( $instructors );
$total = count($instructors);

$posts = get_posts(array(
 'post_type' => 'kgi_personnel',
 'posts_per_page' => $total,
    'post_status' => 'publish',
    'include' => $instructors
));

Thank you in advance,

Ryan

I created a Post Object field type (see attached screenshot post-object-0.png)

How do I output the instructors in order by the selection choices made by the users (see attached screenshot post-object.png)

My query is as follow:

$instructors = get_sub_field( 'instructors');
//var_dump( $instructors );
$total = count($instructors);

$posts = get_posts(array(
 'post_type' => 'kgi_personnel',
 'posts_per_page' => $total,
    'post_status' => 'publish',
    'include' => $instructors
));

Thank you in advance,

Ryan

Share Improve this question asked Dec 11, 2019 at 18:58 user3298611user3298611 535 bronze badges 1
  • Change your field's return format to "Post Object" instead of "Post ID." That way you'll already have the post information in your get_sub_field() call and it will be in the order they selected. – WebElaine Commented Dec 11, 2019 at 19:08
Add a comment  | 

1 Answer 1

Reset to default 3

I actually added these 2 lines and it worked

'post__in' => $instructors,
'orderby' => 'post__in',
发布评论

评论列表(0)

  1. 暂无评论