Home Forums Add-ons Flexible Content Field CPT in Flexible Content


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">
             $the_query = new WP_Query(array(
              'post_type' =>'question_answer'
             while ( $the_query->have_posts() ) :
    		 $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 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'); ?>
                 <?php endwhile; wp_reset_postdata(); ?>  

    And my field is a true/false field within a flexible content field.

    Hope it helps someone else 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘CPT in Flexible Content’ is closed to new replies.