Support

Account

Home Forums Add-ons Options Page Using library 'uploadedTo' on an options page

Solved

Using library 'uploadedTo' on an options page

  • Hi,

    When I add an image field to an options page created with ACF, I want to be able to select only the images uploaded to that options page. But when I set the ‘library’ to ‘uploadedTo’, the media library shows all uploaded images that are not connected to a page. Also, the images I upload are not connected to the settings page. Is this a bug in ACF, or is this the expected behaviour?
    It is possible the same issue exists for file fields, I have not checked this.

    Regards,
    Tim Havinga

  • Uploaded to post is something that’s built into WP. The post ID is set as the parent of the attachment. There isn’t any way to do this for options pages or for that matter, terms in a taxonomy or any other object in WP.

    I do not recall any topics ever being submitted here that included a solution for this.

    I’m not even sure that it would be possible at all and I’m not sure where you’d start looking. The upload uses the built in WP file upload and works through AJAX. You might be able to add some filters during the process to detect that an attachment is being uploaded for a specific options page, then you could probably add a post meta field to the attachment to indicate what it was uploaded to, and finally you could probably filter the images that are being displayed during the AJAX call that shows these images to only show others that were uploaded for the same options page. However, this is all guess work, you’re probably looking at several hours of research and testing to get each part of this working, that is if it will work, and there’s no way of knowing until you try it.

  • Alas, I am not experienced enough it comes to WP and the inner workings of the media library. So it is above my head to resolve this.

    The issue remains that media uploaded to an options page is not marked as attached to a post (or anything), therefore it could be removed in an over-enthousiastic cleanup.

  • Even if this could be done in some way so that it would work with ACF image fields, there still would not be any way to prevent images being “removed in an over-enthusiastic cleanup.” WP uses the post_parent in the _posts table to mark an image uploaded to a post. WP has no built in mechanism for uploading or adding attachments to any other type of object. This is something that’s not likely to change, I doubt that you’ll ever see a built in WYSIWYG on a term or anywhere else in WP for that matter. Also, the post_parent field requires an integer that is assumed to be another post ID, so anything created would be a work-a-round that would be outside of anything that WP would recognize.

    There is one solution that I just thought of. There is the ability for ACF to save field values of options pages as related to a “post” (see the ‘post_id’ argument https://www.advancedcustomfields.com/resources/acf_add_options_page/) and I think that this will make it work the same, I just tested this and I know it works. The thing here is that you need posts, of some type, to store the values on and this means creating some type of post type for holding the options fields. My plugin that lets you create options pages using an admin interface will also let you save fields to the post of the options page settings… https://wordpress.org/plugins/options-page-admin-for-acf/

  • It just so happens that the options page I created is used on one specific page on my website. So, I connected the options page to that page. Not ideal, but it works. Thanks for the help and pointing me to your cool plugin!

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

The topic ‘Using library 'uploadedTo' on an options page’ is closed to new replies.