Support

Account

Home Forums Front-end Issues Hide page's ACF oEmbed field if Post Object has value for different ACF oEmbed

Helping

Hide page's ACF oEmbed field if Post Object has value for different ACF oEmbed

  • I want to localize a script with a URL for a featured video from a single selected post.

    The post is in a post object ACF field for the homepage. On the backend, I want to show or hide an oEmbed field for the homepage based on the existence of a value for an oEmbed field of the selected post.

    The filter I am trying to set up is:

    • If the selected post (Post Object) has a value for an oEmbed ACF field, hide the next field on the homepage backend for an oEmbed.
    • If the selected post does not have a value for an oEmbed ACF field, show the homepage oEmbed field on the backend.

    How would I do this? In searches, I may not be describing the action properly because none of the results I can find seem relevant to what I am trying to do.

  • I don’t think you can do this just by localizing a script, and if you do then it would really only work after the post was saved. For example, if the post object field is empty then there would be no value. If the value in the post object changes then how would you change it? To localize the script you would need to include a list of every post that has a value in its oembed field.

    This is like conditional logic, but conditional logic will not work across posts.

    I know this is not the answer that you are looking for, but I would put in the field instructions for the home page oembed field that the video entered will only be used if the selected post does below does not have a video.

    If I really needed to build this I would have to do an AJAX request based on the value in the post object field when that field is changed to see if the selected post has a value in the field and then depending on the response hide or show the other field by applying or removing the same class that ACF uses to hide fields based on conditional logic. I would also build an acf/prepare_field filter for the oembed field on the home page that would show or hide the field using the field rapper classes.

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

You must be logged in to reply to this topic.