admin管理员组文章数量:1289363
I have a post_type of 'interview' and within it is a repeater field 'interview' and sub_fields 'question' and 'answer'. I would like to display all questions and answers from all interviews and orderby question, perhaps alphabetically. So that on the actual page you see different answers from the same question.
Right now I am able to list all questions and answers but any attempt I make at orderby just orders them by question within the post and not over all.
What I want:
- Q1 from Post 1
- A1 from Post 1
- Q1 from Post 2
- A1 from Post 2
- Q2 from Post 1
- A2 from Post 1
- Q2 from Post 2
- A2 from Post 2
What I am getting:
- Q1 from Post 1
- A1 from Post 1
- Q2 from Post 1
- A2 from Post 1
- Q1 from Post 2
- A1 from Post 2
- Q2 from Post 2
- A2 from Post 2
I am using wp_query with args for post_type but it just seems that I'm actually returning just a list of all posts not a list of all custom fields because they stay grouped together by post.
<?php
$args = array(
'posts_per_page' => -1,
'post_type' => 'interview',
'orderby' => 'question',
'order' => 'DESC'
);
$answer_query = new WP_Query($args); ?>
<?php
while ($answer_query->have_posts()): $answer_query->the_post();
if( have_rows('interview') ):
while( have_rows ('interview') ): the_row();
// Questions and Answers
if( get_sub_field('question')){
$question = get_sub_field('question');
}
if( get_sub_field('answer')){
$answer = get_sub_field('answer');
}
if( get_sub_field('qaid')){
$qaid = get_sub_field('qaid');
}
echo '<div class="question_container">';
echo '<div class="question"><h3>' . $question . '</h3></div>';
echo '<div class="answer">' . $answer . '</div>';
echo '</div>';
endwhile;
endif;
endwhile;
wp_reset_postdata();
?>
版权声明:本文标题:wp query - How can I display a custom field from all posts and order them individually from their parent post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741411388a2377255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论