Site logo

Archived topic

Need to allow results from search in a custom Gutenberg block

3 replies · Started by Frederique on December 20, 2021

Viewing posts 1–4 of 4

Hithere!
We add a custom block like an accordion in pages but we need some advice to get search from their content.
For e.g when we have some search here > https://www.colormyweb.pro/Buxerolles/?s=dechet
the first result is the title of the concerned page but we notice we can't load some results from the content in the tabs with other searching requests.

Accordion blocks have been built with ACF and nothing very special about that...

In summary, how could we get some queries from accordion tabs ?
Thanks a lot for helping understanding the best way to do so :)

----

(see code in the view maybe helps)

<?php
/**
 * Affichage du HTML dans le block
 *
 * @package acf-gutenberg-blocs
 * @author Colormyweb
 * @since 1.0.0
 */

// create id attribute for specific styling
$cmw_acc_id = 'cmw-accordion-' . $block['id'];
 
if( !empty($block['anchor']) ) {
    $cmw_acc_id = $block['anchor'];
}
 
// Create class attribute allowing for custom "className" and "align" values.
$cmw_className = 'cmw-accordion';
if( !empty($block['className']) ) {
    $cmw_className .= ' ' . $block['className'];
}
if( !empty($block['align']) ) {
    $cmw_className .= ' align' . $block['align'];
}

$align_class = "";
 
//get repeater field name
if( have_rows('accordion') ): ?>
    <div class="<?php echo esc_attr($cmw_className); ?> <?php echo $align_class; ?>" id="<?php echo $cmw_acc_id; ?>">
        <?php
        //whilst we have repeating fields
        while ( have_rows('accordion') ) : the_row(); 
            //vars
            $acc_title = get_sub_field('accordion_title');
            $acc_content = get_sub_field('accordion_content');
            ?>
            
            <h2 class="cmw-acc-title">
            <?php echo ($acc_title); ?>
            </h2>

            <div class="cmw-acc-panel" style="display: none;">
            <?php echo wp_kses_post($acc_content); ?>
            </div>				  
            
        <?php endwhile; ?>
    </div>
<?php endif; // end accordion ?>

That means content is not shown ?
I'm not an expert and try to get it...
What's the gab btw Excerpt and Search results ?
Thanks !

That means content is not shown ?

Yes, thats correct.

This is the bug report here:

https://core.trac.wordpress.org/ticket/47637

Until that is resolved, Excerpts will only display content that are Top Level blocks. Anything that is placed inside another block, such as a Group Block, a GB Container Block or your custom ACF Accordion Block cannot be included in the Excerpt.

And as Search Results show the Title and the Excerpt you won't see that content in the search field either.

This archived topic is closed to new replies.