Support

Account

Home Forums General Issues Conditional display on specific fields based on post type

Solved

Conditional display on specific fields based on post type

  • I have a field group that I’m displaying on multiple post types but there are specific fields I’d like to display only on specific post types. Some are fields inside repeater fields others are “Normal” fields.

    For example something like this

    Radio buttons (Post types A and B)
    Text Field (Post types A and B)
    Date time picker (Post Type B only)
    Repeater field 1 (Post types A and B)
    —Image Field (Post types A and B)
    —Url Field (Post types A and B)
    —Date time picker (Post Type B Only )
    Repeater field 2 (Post types A and B)
    —Image Field (Post types A and B)
    —Url Field (Post types A and B)
    —Date time picker (Post Type B Only)

  • To do this you are going to need to create acf/prepare_field filters for the fields in question.

    You should be able to use the same filter for multiple fields. In your filter you will need to get the post_type that is being added or edited. This information may be available in global $post or you may need to look in $_GET for the values (I’m not sure if the values will be in global $post when creating a new post.

    You check the post type and then either return the $field or return false depending on if you want the field to be used or not.

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

You must be logged in to reply to this topic.