Support

Account

Home Forums General Issues Filter based on get_field_object

Helping

Filter based on get_field_object

  • Hi,

    I’m trying to create a filter based on get_field_object in an archive file.

    Calling it like this:

    $field = get_field_object("mytaxonomy", false, false);

    My problem is that as soon as the filter returns no results, I don’t get a response from get_field_object as there are no object_ids.

    I could fix this by adding a hardcoded entry, like this:

    $field = get_field_object("mytaxonomy", 25, false);

    But it doesn’t feel very clean. Neither does using a temporary $wp_query that matches all posts with this taxonomy? I wonder if someone in the community got a clean solution?

    Thank you!

  • If a field may not be set then to get the field object you need to use the field key instead of the field name. Using the field key will always return then correct field object.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Filter based on get_field_object’ is closed to new replies.