Cwicly Tutorials

Cwicly Tutorials

Build with the Cwicly site builder

Query ACF with boolean

I wanted to use a boolean to show particular posts on my frontpage and others not.

But on my posts-page I want to show all the posts.

So I created an Advanced Custom Field with the name Frontpage which I can set while creating/editing my post.

This is how I solved it.

I created a radion-button field like below:

When the choice is Yes on my post I want to show it on the frontend.

When creating a query you have to set it up like this on the Meta Query Tab:

To let it work you have to add a codeblock BEFORE the query element with this code:

Where in line 3 you have to put your own query-id which you can find by right clicking on the query element in your Cwicly Navigator:

Good luck!

The Code:

<?php
add_filter( 'cwicly/query/args', function( $query_args, $attributes, $id ) {
    if ($id === 'query-c995624') {
        $query_args['meta_query'][0]['value'] = 'ja';
    }
    return $query_args;
}, 10, 3 );
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Design by  Lijn-B

Made with Cwicly