Sage – Add Block Ressources (ACF, Bootstrap)

Plugins

FacetWP
FacetWP - Submit button

resources\functions.php

// add blocks (ACF)
require_once("add-blocks.php");

resources\add-blocks.php

function my_acf_init()
{
    acf_update_setting('google_api_key', 'AIzaSyAla6ga3Cinggk981OyWSnWnziEocaB_pU');
    // check function exists
    if (function_exists('acf_register_block')) {

        acf_register_block(array(
            'name'                => 'Resources',
            'title'                => __('Resources'),
            'description'        => __('Resources Block'),
            'render_callback'    => 'my_acf_block_render_callback',
            'category'            => 'formatting',
            'icon'                => 'admin-comments',
            'keywords'            => array('Resources, News, Filter'),
        ));
    }
}

add_action('acf/init', 'my_acf_init');

function my_acf_block_render_callback($block)
{
    // convert name ("acf/testimonial") into path friendly slug ("testimonial")
    $slug = str_replace('acf/', '', $block['name']);

    // include a template part from within the "template-parts/block" folder
    echo \App\template("blocks/{$slug}", array('block' => $block));
}

add_filter('render_block', function ($block_content, $block) {
    if ('acf/featured-pages' === $block['blockName']) {
        remove_filter('the_content', 'wpautop');
    }

    return $block_content;
}, 10, 2);

resources\views\blocks\xxx.blade.php

<!-- Slider Homepage -->
<?php
// create align class ("alignwide") from block setting ("wide")
$align_class = $block['align'] ? 'align' . $block['align'] : '';
//var_dump($param["align"]);
?>

<div class="resources__wrapper <?php echo 'align' . $param["align"] ?>">

    <div class="row">
        <div class="col-sm-3">
            <div class="label-filter">
                Filter by Tags
            </div>
            <button class="fwp-reset" onclick="FWP.reset()">clear all</button>
        </div>
        <div class="col-sm-9">
            @php
            echo do_shortcode('[facetwp facet="categories"]');
            @endphp
        </div>
    </div>
    <div class="row">
        <div class="col-sm-3">
            <div class="label-filter">
                Search by keyword
            </div>
        </div>
        <div class="col-sm-9">
            @php
            echo do_shortcode('[facetwp facet="search"]');
            @endphp
            <button class="fwp-submit" data-href="/resources/">GO</button>
        </div>
    </div>

    @php

    $q = new WP_Query( array(
    'post_type' => 'post',
    'posts_per_page' => -1,
    'post_status' => "publish",
    'facetwp' => true,
    ) );
    $wp_query = $q;

    @endphp

    @if ($q->have_posts())
    <div class="card-columns">
        @while ($q->have_posts())
        @php
        $q->the_post();
        //var_dump('partials.content-'.(get_post_type() == 'resources' ? get_post_type() : get_post_format()));
        @endphp
        @include ('partials.content-'.(get_post_type() == 'resources' ? get_post_type() : get_post_format()))
        @endwhile

        @php(wp_reset_postdata())
        @else
        <div class="alert alert-warning">
            {{ __('Sorry, no posts were found.', 'sage') }}
        </div>
        @endif
    </div>

</div>

Facet WP

{"facets":[{"name":"categories","label":"Categories","type":"checkboxes","source":"tax\/post_tag","source_other":"","orderby":"count","count":"100","parent_term":"","hierarchical":"no","show_expanded":"no","ghosts":"yes","preserve_ghosts":"yes","operator":"and","soft_limit":"100"},{"name":"search","label":"Search","type":"search","source":"","search_engine":"","placeholder":"test","auto_refresh":"yes"},{"name":"new_facet","label":"New Facet","type":"checkboxes","source":"post_type","parent_term":"","hierarchical":"no","show_expanded":"no","ghosts":"no","preserve_ghosts":"no","operator":"and","orderby":"count","count":"10","soft_limit":"5"}],"templates":[{"name":"example","label":"Example","query":"","template":"","layout":{"items":[{"type":"row","items":[{"type":"col","items":[{"type":"item","source":"post_title","settings":{"link":{"type":"post","href":"","target":""},"prefix":"","suffix":"","border":{"style":"none","color":"","width":{"unit":"px","top":0,"right":0,"bottom":0,"left":0}},"background_color":"","padding":{"unit":"px","top":0,"right":0,"bottom":0,"left":0},"text_color":"","text_style":{"align":"","bold":false,"italic":false},"font_size":{"unit":"px","size":0},"name":"el-nqm5vp","css_class":"","is_hidden":""}}],"settings":{"border":{"style":"none","color":"","width":{"unit":"px","top":0,"right":0,"bottom":0,"left":0}},"background_color":"","padding":{"unit":"px","top":0,"right":0,"bottom":0,"left":0},"text_color":"","text_style":{"align":"","bold":false,"italic":false},"font_size":{"unit":"px","size":0},"name":"el-463kx","css_class":""}}],"settings":{"grid_template_columns":"1fr","border":{"style":"none","color":"","width":{"unit":"px","top":0,"right":0,"bottom":0,"left":0}},"background_color":"","padding":{"unit":"px","top":0,"right":0,"bottom":0,"left":0},"text_color":"","text_style":{"align":"","bold":false,"italic":false},"font_size":{"unit":"px","size":0},"name":"el-919qf9","css_class":""}}],"settings":{"num_columns":1,"grid_gap":10,"border":{"style":"none","color":"","width":{"unit":"px","top":0,"right":0,"bottom":0,"left":0}},"background_color":"","padding":{"unit":"px","top":0,"right":0,"bottom":0,"left":0},"text_color":"","text_style":{"align":"","bold":false,"italic":false},"font_size":{"unit":"px","size":0},"name":"el-00offp","css_class":"","custom_css":""}},"query_obj":{"post_type":[{"label":"Posts","value":"post"}],"posts_per_page":200,"orderby":[],"filters":[]},"modes":{"display":"visual","query":"visual"}}]}