Support

Account

Home Forums Gutenberg Gutenberg Block with ACF Pro – By taxonomy

Unread

Gutenberg Block with ACF Pro – By taxonomy

  • Hello everybody !

    I based myself on this tutorial to create a Gutenberg block and display my custom post type “Projects”.

    I would like to adapt it for another custom post type “FAQ”.
    We would, as in the previous one, be able to search for specific posts. And I would like to add the possibility of displaying all the posts by filtering with one or more taxonomies.

    Would anyone see how to do it?

    I tried the code below but Gutenberg doesn’t seem to save it. When I want to edit my page on which I added the block and selected a taxonomy, my filter is empty.

    $argType = get_field( 'faqs_loop' );
    
    if( $argType == "count" ) :
        $topics = get_field( 'faqs_categories' );
      $args = array( 
        'orderby' => 'title',
        'post_type' => 'faq',
        'tax_query' => array(
            array(
                'taxonomy' => 'categorie_faq',
                'field' => 'slug',
                'terms' => $topics,
            )
        )
      );
    
    else:
      $faqs = get_field( 'faqs_select' );
      $args = array( 
        'orderby' => 'title',
        'post_type' => 'faq',
        'post__in' => $faqs
      );
    endif;
    
    $the_query = new WP_Query( $args );
    
    ?>
    
        <div class="site_list_post col-12 faq">
            <div class="d-flex row">
    
            <?php if( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
            <article class="post col-12 mb-30">
                    
    				
    			
    					<h2>
                            <?php the_title(); ?></a>
    					</h2>
                        <?php the_content(); ?>
                        <?php the_terms( get_the_ID() , 'categorie_faq' );  ?>
                        
                              
                             
                                
       
    					</article>
          
        
        
        <?php endwhile; ?>
        <?php endif;?>
                                  </div>
                                  </div>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

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.