Hide a loop item based on ACF select option choice

[ad_1]

Hello, I will try to explain this the best I can. I am using Elementor Pro and ACF. I have created a custom post type of “reviews”. Using Elementor, I made a loop block that features the reviews. I added a field to the reviews with the select field called “client\_status” – the two options for the selection being “Current” & “Past”. The idea is that when a client cancels with us, I want the ability to just select “past” so the review is taken out of the loop.

I have tried every which way to achieve this using PHP and cannot figure it out. I am pretty new in PHP. My latest effort was this and it did not work.

`function add_hide_section_class() {`

`$client_status = get_field(‘client_status’);`

`if ($client_status == ‘Past’) {`

`echo ‘<style>#hidden-section {display: none;}</style>’;`

`}`

`}`

`add_action(‘wp_head’, ‘add_hide_section_class’);`

I tried using the plugin “Dynamic Visibility for Elementor” and found partial success. It does remove the review with the option set to “Past” but it just sets visibility:hidden, instead of display:none. It’s like the “past” review still being there but the opacity set to 0. The space it occupied is still occupied.

Here is a screenshot – [https://ibb.co/fS5pSF4])

Any help would be appreciated! Thank you.

[ad_2]
2 Comments
  1. Create a radio button in ACF for client_status (‘past’ or ‘current’)

    Specify the appropriate client_status meta field value in your Elementor loop or create a custom WP_Query for it using:


    meta_query => array(
    ‘key’ => ‘client_status’,
    ‘value’ => ‘”current”‘,
    ‘compare’ => ‘LIKE
    ),

    Hiding it via CSS is a bit of a hatchet job 😉

  2. Looks like you’ve solved it, but if you have more problems like this in the future I’d absolutely recommend dynamic.ooo – their plugin will let you filter out posts by custom field directly from their ‘Dynamic posts’ widget.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer