• Resolved florettech

    (@florettech)


    Hello!

    I am trying to keep pages that have a specific ACF field value from being indexed. I’ve followed the guide here:
    https://webdevstudios.com/2021/02/09/wp-search-with-algolia/#excluding-individual-posts

    (The code in my functions file looks exactly like the example except I am using a slightly different name for my ACF field)

    I now have pages with the ACF exclusion field checked that are still showing up in search.

    I’ve tried bulk reindexing from the plugin settings “Search” page and have also reindexed All Posts (index name: searchable_posts) from the plugin settings “Autocomplete” page.

    Nothing seems to remove these records from search. Am I missing something? Is there a cache issue or do I need to push settings perhaps?

    Many thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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

    Thread Starter florettech

    (@florettech)

    @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!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Definitely one way to have that work. An alternative would have been something like this:

    if ( 1 === (bool)$excluded ) {

    However, I’ll take whatever works.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Exclude pages based on ACF field value’ is closed to new replies.