Skip Navigation

[Resolved] repeating fields of related posts

This thread is resolved. Here is a description of the problem and solution.

Problem:
Client wants to store related posts in a custom field and to then be able to output content of those related posts when viewing the first post (a simple bespoke solution that doesn't involve post relationshipts).

Solution:
Store the related post IDs in repeating numeric fields, i.e. add as many as there are related posts.

Then in the Content Template for this post type, to display content from the related posts use the wpv-for-each shortcode to loop over the numeric fields which store the post IDs which can then be used as the id attribute of the shortcodes used to output the required fields.

An example is below: https://toolset.com/forums/topic/repeating-fields-of-related-posts/#post-628355

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

This support ticket is created 6 years, 8 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 5 replies, has 2 voices.

Last updated by Franco Calcagni 6 years, 8 months ago.

Assisted by: Nigel.

Author
Posts
#627687

Tell us what you are trying to do? we need to allow for each custom post to create a grid of related posts by selecting manually the URL of each post and display them in a grid element with thumbnail, title and link.
We know that in your beta version of new release it will be available a "related post" field but how can we build that feature in the meantime with the existing tools?

What is the link to your site? the page where the grid shall be displayed is this: hidden link in the NEWS tab content.

Thanks for your help.
Franco

#627807

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Franco

If you are connecting posts of the same type, I would create a repeating numeric field which stores the ID is related posts.

So when you are editing one post you can add as many related-id fields to that post as you like.

Then in the content template for a post, where you want to display the related posts you can use the wpv-for-each shortcode to loop over the related-id fields. You will be able to use this field for the id attribute of the Views shortcodes to output the title, the image, and to create a link.

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-for-each

Does that make sense or do you need more help with that?

#627811

Hi Nigel,
thanks for the info.. I will do as you wrote and if you don't mind I keep this topic open until I get the solution working.
Thanks,

Franco

#627873

Hi Nigel,
i need some help with the view structure because I am not able to define the query filter of only the post ID that are recalled in the custom post.

Do you have any code example?

In the layout I created the following code that recalls the view data but it doesn't work because I don't find where in the view I can say that the filter shall consider only the ID that are stored in the "related-posts" field

<ol class="post-grid">
    <li>dddd</li>
        [wpv-for-each field="wpcf-related-posts"]<li>[wpv-view name="grid-related-post"]</li>[/wpv-for-each]</ol>

Thanks

Franco

#628355

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Franco

A View is not required here.

Say I have a post type of "projects" and a repeating numeric field of "related-posts".

I create a template to display projects (either a Views Content Template, or a Layouts template), and then I add code such as the following to output the related posts:

[wpv-for-each field="wpcf-related-posts"]
[wpv-post-title id="[types field='related-posts']"] <-- output post title of a related post -->
[wpv-post-featured-image id="[types field='related-posts']"] <!-- output featured image of a related post -->
[/wpv-for-each]

That will loop over each of the related post fields and output content from the related post itself, by using the id attribute to switch context from the current post to the target post. You can use this to output any field from the related posts.

#629518

problem solved.