Home › Forums › Add-ons › Flexible Content Field › CPT in Flexible Content
Hi.
Can someone point me in the right direction please. I’m using Flexible Content to allow my client to create sections of content.
I have created a Custom Post Type called ‘Questions and Answers’ (see screenshot). I would like the client to be able to add a row (I’m using flexible content) which will display all the posts within the CPT. At the moment it only allows the customer to pick individual posts – rather than the whole post type (see screenshot). Is there a way I can set it to show all the posts dynamically somehow?
Hope this post makes sense – I’m just learning about flexible content (and loving it).
I’ve figured it out π
In my main template
// Question and Answer section
if( get_row_layout() == 'questions_and_answers_section' )
get_template_part('partials/stripe', 'questionandanswer');
In my Partials
<section class="section-white qandasection">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2 st-accordion">
<h3>General Questions & Answers</h3>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php
$the_query = new WP_Query(array(
'post_type' =>'question_answer'
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
$post = $post->ID
?>
<div class="well-default panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h3 class="panel-title"> <a role="button" data-toggle="collapse" data-parent="#accordion" href="#<? the_ID(); ?>" aria-expanded="true" aria-controls="collapseOne" class="collapsed"><?php echo the_field('question'); ?></a> </h3>
</div>
<div id="<? the_ID(); ?>" class="panel-collapse collapse inn" role="tabpanel" aria-labelledby="headingOne" aria-expanded="true">
<div class="panel-body">
<?php echo the_field ('answer'); ?>
</div>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
</div>
</div>
</section>
And my field is a true/false field within a flexible content field.
Hope it helps someone else π
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Weβre reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.