Skip Navigation

[Gelöst] show repeating fields in view from parent cpt if exist

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

Problem:

The issue here is that he user wanted to display fields from the parent post if that child post has a parent.
Solution:

To do this just use the following shortcode.

[wpv-conditional if="( '[wpv-post-datei name='_wpcf_belongs_projekte_id']' ne '' )"] 
<a href="[types field='datei' link='true' output='raw'][/types]" titel="[types field='datei' link='true' output='raw'][/types]"><i class="fas fa-download"></i>  [types field='download-titel'][/types] [types field='art'][/types] Größe: [types field='size'][/types]</a>
[/wpv-conditional]
  
[wpv-conditional if="( '[wpv-post-datei name='_wpcf_belongs_projekte_id'']' eq '' )"] 
<a href="[types field='datei' link='true' output='raw'][/types]" titel="[types field='datei' link='true' output='raw'][/types]"><i class="fas fa-download"></i>  [types field='download-titel'][/types] [types field='art'][/types] Größe: [types field='size'][/types]</a>
 [/wpv-conditional]

Where you will replace _wpcf_belongs_projekte_id with _wpcf_belongs_{yourcptslug}_id

This support ticket is created vor 6 Jahren, 9 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Dieses Thema enthält 9 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von alexd-6 vor 6 Jahren, 8 Monaten.

Assistiert von: Shane.

Author
Artikel
#619053
Screenshot 2018-02-23 14.19.19.png

I am trying to:
show repeating fields in view from parent cpt if exist.

i have a parent "projekt" with repeating child fieldset/cpt "pdownloads". In Child "objekt" of parent "projekt" i want to show the "pdownloads" of the same parent "projekt".

How can i do this? My way: i created a view (screenshot)

Whats wrong?

best regards - alex

#619104

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Alex,

Thank you for contacting our support forum.

Actually what you can do to check if the child has a parent is to use our conditional shortcode.

[wpv-conditional if="( '[wpv-post-field name='_wpcf_belongs_job_id']' ne '' )"] 

repeatable fields

[/wpv-conditional]

[wpv-conditional if="( '[wpv-post-field name='_wpcf_belongs_job_id']' eq '' )"] 

some other content

[/wpv-conditional]

From the example above you see that i have the slug _wpcf_belongs_job_id , this references the custom field that the parent information is stored. Now in your case you will use "_wpcf_belongs_{parent-cpt_slug}_id" where you will replace the {parent-cpt_slug} with the slug of your CPT.

For more information on the conditional shortcode please see the link below.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

Please let me know if this helps and if there are further queries.

Thanks,
Shane

#622024

Hey Shane,

where in my View i can put it in? - When i do it in the Loop it doesn't help.

here is my code:

[wpv-conditional if="( '[wpv-post-datei name='_wpcf_belongs_projekte_id']' ne '' )"] 
<a href="[types field='datei' link='true' output='raw'][/types]" titel="[types field='datei' link='true' output='raw'][/types]"><i class="fas fa-download"></i>  [types field='download-titel'][/types] [types field='art'][/types] Größe: [types field='size'][/types]</a>
[/wpv-conditional]
 
[wpv-conditional if="( '[wpv-post-datei name='_wpcf_belongs_projekte_id'']' eq '' )"] 
<a href="[types field='datei' link='true' output='raw'][/types]" titel="[types field='datei' link='true' output='raw'][/types]"><i class="fas fa-download"></i>  [types field='download-titel'][/types] [types field='art'][/types] Größe: [types field='size'][/types]</a>
 [/wpv-conditional]
#622117

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Alex,

Would you mind providing me with admin access to the website so that I can take a look at the view?

The private fields will be enabled.

Thanks,
Shane

#622123
#622155

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Alex,

From your code i dont see where its a field from the parent you want to display but rather a field from another child from that parent.

I see that youre looking for the Datei field is this correct?

Please let me know.
Thanks,
Shane

#622158

Hi Shane,

oh sorry its the view "Downloads Objekt" - my fault.

there is the field [types field='datei' link='true' output='raw'][/types] which should target the File stored in parent "Projekt"

thx - alex

#622168

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Hi Alex,

Please have a look and let me know if its ok now.

Thanks,
Shane

#622170

Hi Shane,

yes - but you dont change the code? What was wrong?

thx a lot - alex

#622176

Shane
Supporter

Sprachen: Englisch (English )

Zeitzone: America/Jamaica (GMT-05:00)

Screen Shot 2018-03-05 at 10.53.22 AM.png
Screen Shot 2018-03-05 at 10.51.09 AM.png

Hi Alex,

Ahh yes I didn't what I did was to add a filter to the view for the parent projekt , since the objekte and the pdownloads share the same parent cpt, so essentially pdownloads and objekte are siblings. So if I found the parent of the current objekte that i'm viewing then I can use that parent information to find the pdownload.

I did that by adding this filter. See Screenshot

Then I filtered the view using the shortcode parameter.

[wpv-view name="downloads-objekt" wpvprchildof="[wpv-post-id id='$projekt']"]</div>

So that is all that was needed 🙂 I was a bit unsure earlier but then you pointed me to the right view that I should be looking at.

#622179

Hi,

oh yes thats nice. 😉

thank you very much

einen schönen Gruß - alex