• I created a custom post type for different office locations, but I didn’t want to further categorize the locations, so on my website’s “Locations” page, I’m using the option to filter by custom field, which is currently state.

    When a location is closed, rather than unpublishing the page corresponding to the location, I would like to exclude the location from the list using another custom field – a true/false checkbox called “is_location_active.”

    To list VA locations, I use

    [catlist post_type="ihmc_locations" numberposts=-1 customfield_name=state customfield_value=VA order=ASC conditional_title=Virginia]

    It works great! But now that I have a location closing, I want to be able to deactivate it, not have it appear in the list of locations, but still have it accessible to users who end up on that page.

    I tried this:

    [catlist post_type="ihmc_locations" numberposts=-1 customfield_name=state,is_location_active customfield_value=VA,1 order=ASC conditional_title=Virginia]

    and I also tried:

    [catlist post_type="ihmc_locations" numberposts=-1 customfield_name=state customfield_value=VA order=ASC conditional_title=Virginia customfield_name=is_location_active customfield_value=1]

    The former code didn’t work at all – no Virginia locations showed up. The latter piece of code worked, but only the final occurrence of customfield_name and customfield_value was used, so the inactive location was not on the list, but locations in states other than VA were on the list.

    I’m not sure if it only uses the last customfield_name and customfield_value, or if it somehow creates an “OR” relationship, so it lists anything that with VA as the state OR anything with a value of 1 for is_location_active.

    How can I still list locations by custom field and also filter out posts that are inactive?

    https://wordpress.org/plugins/list-category-posts/

Viewing 1 replies (of 1 total)
  • I don’t know exactly how the plugin treats multiple values, but I don’t think either of the ways you tried are supposed to work.
    As a simple workaround, have you considered setting the value of the customfield named ‘state’ to something like ‘VAinactive’?
    Users could still see the post if they land up on it, but a selection of customfield_name=state customfield_value=VA would not show it.

Viewing 1 replies (of 1 total)

The topic ‘Filter by ACF custom field’ is closed to new replies.