Exclude pages based on ACF field value

[ad_1]

Hmm. That example snippet definitely looks like it’s covering both searchable posts index and the wp_posts_post index for autocomplete.

Have you verified what’s getting stored and returned in your ACF field? As is with the snippet, it needs to store boolean true, in the form of 1 to be marked excluded.

If your field is storing say '1' as a string, then that check would fail because boolean 1 is not the same as string 1

@tw2113 Thank you for your quick response! You were spot on.

Looking back, I had created the field as an ACF True/False field (not a checkbox as described in the article), which stores as an integer 0 or 1 not as a boolean.

Changing the line:
if ( 1 === $excluded ) {
to:
if 1 == $excluded ) {
did the trick.

Many thanks!

 

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