Skip Navigation

[Gelöst] How to organize gallery for multipurpose (and external) usage

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem: I would like to use CRED to allow my site Users to upload multiple images, and associate those images with CPTs. Some of those CPTs are child posts, some are parents, some are grandparents. What is the best way to associate the images with all levels of the CPT hierarchy?

Solution: It depends on your site's requirements. There are several things to consider.
- It is easier to create custom search filters using custom fields attached to the same post type shown in the View.
- However, it is not possible to use repeating fields in child posts in the current stable version of Types. The new beta M2M features will address some of this issue.
- Taxonomies can be used to relate the images to multiple CPTs, but they must be managed by your Users.
- Galleries and Carousels in Divi Builder have limited options for filtering the results, and it is not possible to use shortcodes as filters. So Divi cannot access custom fields effectively in the Gallery or Carousel module.
- Elementor ACF Gallery modules may or may not work with Types custom fields. Types custom fields are stored in the postmeta table using the previx "wpcf-".

This support ticket is created vor 6 Jahre, 1 Monat. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Artikel
#619421

Goal is to get possibility to use specific images in several post types (and archives) in custom mode (so, with 'external gallery tools/plugins' - example, Divi Gallery or Elementor Carousel).

- First issue (limitation) is fact that I cannot enable 'multiple photos/videos' if CPT parent/child relationship is in usage. So, how to enable multiple media upload?

- Second starting point is vertical ('Sites' - mean physical locations) and horizontal ('Places' - mean 'businesses, events and similar CPT) structure of created CPT. So, how to assign every photo/video in same time to 'Site' and 'Place' (obviously, another 'child CPT')?

QUESTION

So, what is the best option (i it is some) to get gallery assigned to both (Site and Place), but also to be available to be used within Template created by othe page builder than layouts (ie Divi or Elementor), as there I can't use for that purpose shortcodes? How to make it?

#619526

First issue (limitation) is fact that I cannot enable 'multiple photos/videos' if CPT parent/child relationship is in usage. So, how to enable multiple media upload?
In wp-admin, you can go to Media Library > Add New and upload multiple items at the same time. Then in the post editor screen, you can select from existing items from the Media Library when filling in your custom fields. In a CRED form, unfortunately it is only possible to upload files one by one.

So, how to assign every photo/video in same time to 'Site' and 'Place' (obviously, another 'child CPT')?
I'm not sure I understand what you mean by horizontal and vertical, but it sounds like "Site" is a parent post and "Place" is a child of "Site". Is that correct? If so, then custom code will be necessary to copy fields from a parent to the child, and potentially to other child post types. If Places are created with CRED, then the CRED API cred_save_data can be used to automatically set custom field values in a child post from a parent post. Here is a simple example:

add_action('cred_save_data', 'copy_fields_from_parent_action',10,2);
function copy_fields_from_parent_action($post_id, $form_data) {
  if ($form_data['id'] == 12345)
  {
  //  copy the field "fieldslug" from the parent site into the child post created by CRED
    $site_id = get_post_meta( $post_id, '_wpcf_belongs_site_id', true ); // parent site ID
    $custom_field = get_post_meta( $site_id, 'wpcf-fieldslug', true ); // custom field from site
    update_post_meta($post_id, 'wpcf-field-slug', $custom_field );  // custom field in child
  }
}

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

So, what is the best option (i it is some) to get gallery assigned to both (Site and Place), but also to be available to be used within Template created by othe page builder than layouts (ie Divi or Elementor), as there I can't use for that purpose shortcodes? How to make it?
First, let me say that it is not really possible to use custom fields from Types as images in a Divi Gallery, because Divi does not allow you to insert shortcodes in the Divi Gallery builder. You could insert the images directly from the Media Library, but not using shortcodes. This is a limitation of the Divi integration with Toolset. You can follow the instructions here to create a Slider in Views that loops over repeated image fields:
https://toolset.com/forums/topic/how-to-display-the-pics-i-uploaded-as-a-slider/#post-518295

If you want to include a Gallery in multiple locations, you can insert that Gallery module into any Content Template created by Divi. You can insert a Text Module into the Content Template using the Divi Builder, and inside that Text Module you can use Toolset shortcodes.

#619547

Unfortunately, you completely misunderstood every single point (my bad).

1) For 'multiple photos/videos' issue, I can't understand what was unclear, but I will try to explain again.
- Point is to upload media via CRED (so, forget other options).
- First problem is that I cannot enable 'repeating' media upload feature if field is part of parent/child post. as it is NOT SUPPORTED by Toolset. It mean that in some 'ordinary scenario', I must to limit number of media files upload (ie to 6 times repeated photo upload field, as I cannot enable in one photo upload field 'repeater' option - Toolset say that it must to have unique/single value/entrance).

So, my first part of question was - is it possible to upload multiple photos (media) in some other way than to repeat photo (media) upload field itself (ie 6 times), in the case of parent/child posts? See next - 'child' post type 'Media' (for be clear about purpose of this first question.

2) NO. 'Places' and 'Sites' are child post types of (ie) 'Neighborhood' post type. Example - Manhattan is one of the New York 'Neighborhoods' (parent post type), with Central Park as one of the 'Sites' (physical locations - so, attraction by itself) and with The Loeb Boathouse restaurant as 'Place' (business place - within Central Park). Media (photos/videos) from The Loeb Boathouse are obviously media source for Manhattan, Central Park and The Loeb Boathouse - at the same time.

So, for me sounds logical as one of theoretical possibility, to create 'Media' ('Places' and 'Sites') 'child' post type and to assign to it some taxonomies (if I need it) and to eventually also assign same taxonomies to WordPress Media Library (if needed), to be able to programatically use it by 'external' page builder (ie Divi). It mean that media can be uploaded via CRED and automatically 'sorted' by taxonomies in use.

3) At this point, I should to be able to use in Template created by Divi, its own gallery module as it can assign to gallery only posts by some post type ('Media' CPT) and filter it by posts/authors/taxonomies. In other words, you are wrong, there is the way to use galleries of 'external' page builders (but there is the problem - and that is the main topic).

- So, if I use Access, 'Place' owner (of restaurant) is basically author and I have that parameter.
- Parent post type also make relations and parameters for 'Place', 'Sites' and 'Neighborhood' post types. In other words, restaurant media I can use as gallery media for Central Park and Manhattan (in 'programmatic' way, if I have common parameter).
- Remaining problem is taxonomy (obviously - category) like 'connective/common element'.

If I enable hierarchy of physical location taxonomy (to be capable to do all above) and enable it in CRED (see begin of topic), I cannot avoid possibility of massive mistakes with taxonomy 'checkboxes', as Toolset (also other tools) don't have the mechanism to stop users to makes multiple checks (so, it could be checked Brooklyn and Manhattan - by mistake or intentionally and there is no way how to ovoid and check such mistakes).

QUESTION is essentially - is it some other way than taxonomy to 'connect' all post types and use same media within them by 'external' page builder?

Sorry, for misunderstanding (again). Hopefully, I was now clear (if not, I can try again in other way - as I want to find solution).

#619734
step-1.png
step-2.png

So, my first part of question was - is it possible to upload multiple photos (media) in some other way than to repeat photo (media) upload field itself (ie 6 times), in the case of parent/child posts?
The new M2M feature currently in beta will support repeating fields and repeating field groups more effectively. For now, you must use separate fields, or upload multiple images in a single WYSIWYG field with the Add Media button. However, the images you upload in a WYSIWYG field are saved together, and difficult to split apart into individual image URLs.

I should to be able to use in Template created by Divi, its own gallery module as it can assign to gallery only posts by some post type ('Media' CPT) and filter it by posts/authors/taxonomies. In other words, you are wrong, there is the way to use galleries of 'external' page builders (but there is the problem - and that is the main topic).
Can you show me a full screenshot of this filter in the Divi Builder? The Gallery Module I am familiar with looks like these screenshots. You can select images for the Gallery, but there is no filtering, and there is no way to select items dynamically based on some filter. The Gallery module is static.

#619760

1) I thought that it is clear how I'm not writing about WYSIWYG field, rather about media fields (image/video). There you can see option (see bottom of shot) - "Allow multiple-instances of this field" (Toolset call it 'repeating' field). For 'child' posts - IT CANNOT BE ALLOWED.

2) Yes, you are 101% right about Divi Gallery module, but there are many other ways to make gallery than to use Gallery module - right (one example is - Toolset gallery)?

- Divi (one of the examples (shot 02). If you make Media post type Content Template and set category with 'full content to display' - it will display Gallery Carousel of those post with ALL IMAGES added to post. BTW - module is from Extra theme Divi builder.
- Elementor example (shot 3) - (p.s. not sure that it will work, as module is for ACF - generally should to accept slugs as it works with Pods also, not just with ACF).

#619761
Selection_03.png
Selection_02.png
Selection_01.png

Sorry, forgot images.

#619765

I hope so that it is clear in Divi example that if I choose 'Ordinary post type' and not a 'Media post type' and check 'full content', it will display 'featured image' (I can exclude other fields - Media post type don't have other fields), what in some scenario's also can to work.

- Example 1 (Media post type) - ALL IMAGES from ALL RESTAURANTS in Manhattan will be displayed in Carousel Gallery of Manhattan.
- Example 2 ('normal post type) - featured images from restaurants in Manhattan will play in carousel of Manhattan Gallery.

#619781

1) I thought that it is clear how I'm not writing about WYSIWYG field, rather about media fields (image/video). There you can see option (see bottom of shot) - "Allow multiple-instances of this field" (Toolset call it 'repeating' field). For 'child' posts - IT CANNOT BE ALLOWED.
Yes, I understand you are writing about media fields but it is not possible to use repeating fields in child posts. I hope this is clear. I do not have any code or workaround that will allow you to use repeating image fields in child posts in the current stable release of Types. It is not possible. The only other option I can think of besides WYSIWYG is the many-to-many (M2M) beta plugin release, where repeating field groups are supported. You can find more information about that here: https://toolset.com/2018/02/types-views-and-cred-betas-with-post-relationships-and-repeating-field-groups/
However, the M2M beta does not really help either because there is still no way to access those repeating custom field values in a Divi Gallery or Divi Carousel, as far as I can tell. See below.

- Divi (one of the examples (shot 02). If you make Media post type Content Template and set category with 'full content to display' - it will display Gallery Carousel of those post with ALL IMAGES added to post. BTW - module is from Extra theme Divi builder.
Again, I see no way to add more custom filters in this module. You can only choose from the filters offered by Divi. If Divi is able to explain how to add a custom filter to this module, I will be glad to take a look at that information and let you know what we can do to help with Types and Views.

- Elementor example (shot 3) - (p.s. not sure that it will work, as module is for ACF - generally should to accept slugs as it works with Pods also, not just with ACF).
I'm not really familiar with this plugin's AE ACF Gallery module for Elementor, but I can explain how Types custom field slugs work. Types stores custom field values in the database with a prefix "wpcf-" plus the field slug from wp-admin. In other words, if your field slug in wp-admin is "custom-image", then the database slug is "wpcf-custom-image". You can try using this prefix to see if Types fields are recognized by this plugin.

#619835

1) Thanks, that I asked.

2) External builders

- Elementor - Thanks - that I asked - your answer helps a lot.

- Divi - if solution for Elementor work, than should to work also in Divi with 'hidden link'

However, my question was slightly different (as I think that it can be achieved by itself - without 3rd part plugins). I asked - is it smart to separate media files to Single custom post type (media format) and to assign it as child post to correspondent parent posts? In that way, uploaded media to restaurant automatically belongs to Manhattan Neighborhood - right (or not)?

Sort of the nonsense (that confusing me) is the fact that restaurant media child post type is already grandchild of Neighborhood post types. So, for me looks that I don't need to assign it again (just taxonomies). But issue is here that Divi itself will not filter content (media) by post types (rather will assign to it), but will do it by taxonomies assigned to post types (see my shot above - custom taxonomies are listed and module is per post type).

bbbrrrrrrr - it sound complicated (and it is not). Let's try like this. How you will upload same images only once (in restaurant) and display them in gallery within several other post types? Answer will most likely lead to Views, but point of question is not in Views, rather in - how to organize media fields group?

- only to restaurant post type or
- media child post type of restaurant (theoretically, I should to have much more freedom for customization of web site content/views/forms - right?)?

#619842

I asked - is it smart to separate media files to Single custom post type (media format) and to assign it as child post to correspondent parent posts?
If you assign it as a child to all correspondent parent posts, this will allow you to create a View of these media posts filtered by any parent. You can easily filter a View of child media posts by Neighborhood to create a gallery of all images related to the Neighborhood, or filter by Site to create a gallery of images related to a specific Site, or filter by Place to create a gallery of images related to a specific Place. So I think that part is smart.

On the other hand, managing these relationships is more difficult. Custom code is required to keep these relationships in sync. For example, if you manually select a different parent Site for this Media post in wp-admin, then the parent Neighborhood may no longer be accurate. It requires manual intervention, or custom code.

Answer will most likely lead to Views, but point of question is not in Views, rather in - how to organize media fields group? - only to restaurant post type?
If these custom fields are on the parent Place post, then it is difficult to create a View of Media posts filtered by custom field. In other words, it is more difficult to filter post type A by fields in post type B. For better custom search support, it is better to put the custom fields on the Media post.

However, if any repeating fields are required, then you cannot place those fields on the Media post. As we have already discussed, you cannot use repeating custom fields in a child post type.

- media child post type of restaurant (theoretically, I should to have much more freedom for customization of web site content/views/forms - right?)?
Yes and no, there is no simple answer. Filtering a View of Media posts by a custom field on the Media post is simpler than filtering a View of Media posts by a custom field on the parent Place post. However, as we have already discussed, repeating custom fields are not supported on child post types.

#619897

Thank you. Excellent final elaboration. That's exactly all what I needed (wanted) to know. Thanks again a lot for clear underlines of main points of my doubts.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.