Skip Navigation

[Résolu] How to display ACF Image field of a Parent post into child post

This support ticket is created Il y a 6 années et 1 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

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)

Ce sujet contient 7 réponses, a 2 voix.

Dernière mise à jour par Shane Il y a 6 années.

Assisté par: Shane.

Auteur
Publications
#1129938

Hi, I created a CPT "Channel" who is parent of Standard WP Post.

In this CPT I added an image fied "image_de_profil" with ACF (I use ACF because v5 are more option than toolset).

Now I want to display the image of the right parent channel into the curent Post user are in ?

Unsing Shortcode.

#1130184

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Marc,

Thank you for contacting our support forum.

What you can do is use the shortcode for the ACF field and then pass the parent post ID into it.

Example.


[acf field="field_name" post_id="Parent ID"]

The document below should be able to assist you with getting the parent ID.
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

Please let me know if this helps.
Thanks,
Shane

#1130476

Thank's it work when I added this code :

<img src="[acf field='image_de_profil' post_id='27']">

But I need to get the parent ID of the current post user are in because this a template. The Parent ID change for every single post.

So I need something like this :

<img src="[acf field='image_de_profil' post_id='code that get the right parent ID of the current post']">

But you can't nest shortcode into shortcode ? I think.

#1130714

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Marc,

You will need to get the parent ID dynamically .

The document below shows you exactly how you can get the parent id.
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

Once you've generated the code, just add it to the post_id attribute of the ACF shortcode.

Please let me know if this was clear.

Thanks,
Shane

#1131805

Hi,

I followed the link you provided and I try this :

<img src="[acf field='image_de_profil' post_id='[wpv-post-id item='@rel_cpost.parent']']">

But it's not working, I think is because a shortcode can't be nested into another shortcode.

Maybe I'm wrong, and I missed something on the document you sended, my english is not accurate.

#1132076

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Marc,

This is actually the correct way to do it.

If you split them up like this, does it give the correct result ?
[wpv-post-id item='@rel_cpost.parent']

Does the parent ID show up ?

Try this.

[wpv-post-field name="image_de_profil" id ="[wpv-post-id item='@rel_cpost.parent']
"]

Please let me know if this helps.

Thanks,
Shane

#1132540

If I use only [wpv-post-id item='@rel_cpost.parent'] yes the right ID is showing up.

[wpv-post-field name="image_de_profil" id ="[wpv-post-id item='@rel_cpost.parent']
"]

This is not working.

Do you think it gona work if I use toolset field instead of ACF ? I used ACF because in ACF image field i can set minimum size for my image and file extension etc. I can't do it with toolset or maybe I don't know how to do it.

#1132791

Shane
Supporter

Les langues: Anglais (English )

Fuseau horaire: America/Jamaica (GMT-05:00)

Hi Marc,

It seems that the ACF shortcode doesn't allow for shortcodes to be used as an ID attribute.

You can use a toolset field for the image but your not able to set the image format or dimensions. However when you're displaying the image you can set what dimensions you want the image to display at.

You can try this and let me know if that would work for you.

Thanks,
Shane