Skip Navigation

[Resuelto] Display custom fields created with Toolset in a non-Toolset template for related posts

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to show custom fields from related posts in my custom post templates.

Solution: Use Views to loop over related posts with a post relationship filter. Then output the field values using Types field shortcodes.

Relevant Documentation:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/

This support ticket is created hace 5 años, 11 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por duongN-3 hace 5 años, 11 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#1174516

I've created a custom post type "Drama" with custom fields (ie. synopsis, network info).
I have another custom type "Downloads" that was created with another plugin (WordPress Download Manager).
These 2 types are associated via a relationship.
I'm able to show sections from "Downloads" on the "Drama" post, but I have no idea how to show "Drama" content on the "Downloads" post.

I've tried using Toolset shortcodes from the Content templates and Views inside the WordPress Download Manager templates, but they are not showing. I think PHP code will show though.

#1174860

Hi, in general I would use a View of related Drama posts to display Drama post information. You can use PHP to insert that View in a Download single post. Here's how I would set it up:
- Create a new View of Drama posts. In the Query Filter section, add a post relationship filter. Select your Drama / Downloads relationship and configure it so that the Drama posts are related to the post where the View is shown (which will be a Download post).
- In the Loop Editor, create a loop that displays information about each Drama post using Toolset shortcodes. Choose any loop format you want, and add your own custom HTML and CSS to style the results.
- Insert this View in your custom PHP template for Download posts using the render_view API: https://toolset.com/documentation/programmer-reference/views-api/#render_view

$drama_args = array(
    'id' => 12345,
);
echo render_view( $drama_args );

Replace 12345 with the numeric ID of the View of related Drama posts. You can find that ID in Toolset > Views.

#1175205
Screen Shot 2018-12-31 at 11.03.08 AM.png

Thanks for providing the steps for this Christian!

So I followed the above steps and noticed that the php snippet didn't work.
I tried using the short code for the view instead [wpv views] inside the "Downloads" template and now the associated content is loading!
I've figured out most of it so far, but I've stumbled upon another issue which is related to this.

I'm trying to list the related "people" type from the "drama" type in the view on the "downloads" page, but it's only showing the first person associated. I realize that I need some loop, but I'm having troubles figuring that out.

Here's the code that I have:

  • Title (romanized): [wpv-post-link]
  • [types field='episodes' format='FIELD_NAME: FIELD_VALUE'][/types]
  • [wpv-post-link item="@cast.child"]
  • [wpv-view name="list-of-credits"]
  • [su_expand more_text="Show more" less_text="Show less" height="100" hide_less="no" text_color="#333333" link_color="#0088FF" link_style="default" link_align="left" more_icon="" less_icon="" class=""][types field='synopsis'][/types][/su_expand]
  • Genre: [wpv-post-taxonomy type="genre"]
  • .

#1175234

Are you referring to the wpv-post-link shortcode that displays Sawamura Ikki? A single wpv-post-link shortcode cannot display multiple results. You must create another nested View. You've already done this once, so it should be familiar to you already. The post relationships will be different and the content selection will be People posts, but the process is similar. Then replace the wpv-post-link shortcode with the new View shortcode.

#1175235

Yes, I'm referring to wpv-post-link shortcode that displays "Sawamura Ikki".
Thanks for pointing me in the right direction, I wanted to make sure before I started to implement another view.

Will try it now and let you know!
Thank you!!

#1175815

I had to switch and play around with the settings in the Views to get what I finally needed.

Thanks!

#1175816

My issue is resolved now. Thank you!