Tell us what you are trying to do?
I have a custom post type called Meanings. I need to display other related Meanings posts on the Meanings post pages.
Is there any documentation that you are following?
I've tried looking through the documentation and forum posts.
Is there a similar example that we can see?
Yes, here: hidden link
What is the link to your site?
hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
Since the post-relationship feature in the Toolset can be used to connect two different post types only, it won't be possible to connect two "Meanings" posts.
As a workaround, you can group the similar "Meanings" posts through either a custom taxonomy or another custom post type, for example, "Meanings Collections".
If you decide to use a custom post type "Meanings Collections", you'll be able to create a one-to-many relationship between the "Meanings Collections" and the "Meanings" post type.
( i.e. 1 "Meanings Collections" can have many "Meanings" posts )
After that, you'll be able to use a post view on the single "Meanings" post page, to show all the related "Meanings" posts belonging to the same collection.
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks Waqar. That's very unfortunate Toolset is not capable of this.
Since Pods is capable, the relationships are currently recorded in a Pods field "Related To". I understand Toolset is able to see this field. How can I get it to display the featured image and title+link of this field? I feel like this is very close to a solution.
The two fields I see in Toolset that seem applicable are "related_to" and "related_meanings".
Here is the Content Template
<div class="part">
<div class="hexa">
<div class="hex1">
<div class="hex2">[wpv-post-featured-image]</div>
</div>
</div>
</div>
<div class="meanings-link">
[wpv-post-link]
</div>
And the View
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<table width="100%" class="wpv-loop js-wpv-loop">
<wpv-loop wrap="5" pad="true">
[wpv-item index=1]
<tr>
<td>
[wpv-post-body view_template="loop-item-in-display-meanings-tags" ]
</td>
[wpv-item index=other]
<td>
[wpv-post-body view_template="loop-item-in-display-meanings-tags"]
</td>
[wpv-item index=5]
<td>
[wpv-post-body view_template="loop-item-in-display-meanings-tags"]
</td>
</tr>
[wpv-item index=pad]
<td></td>
[wpv-item index=pad-last]
<td></td>
</tr>
</wpv-loop>
</table>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-layout-end]
Thanks for writing back.
During testing on my website with a Pods relationship field, I was able to show the related posts, using a custom shortcode:
add_shortcode('custom_pod_related', 'custom_pod_related_func');
function custom_pod_related_func( $atts ) {
global $post;
$a = shortcode_atts( array(
'id' => $post->ID,
'field' => '',
'pod' => ''
), $atts );
ob_start();
$pod = pods( $a['pod'], $a['id'] );
//get the value for the relationship field
$related = $pod->field( $a['field'] );
if ( ! empty( $related ) ) {
foreach ( $related as $rel ) {
echo '<div class="part">
<div class="hexa">
<div class="hex1">
<div class="hex2">
'.do_shortcode('[wpv-post-featured-image item="'.$rel[ 'ID' ].'"]').'
</div>
</div>
</div>
</div>
<div class="meanings-link">
'.do_shortcode('[wpv-post-link item="'.$rel[ 'ID' ].'"]').'
</div>';
} //end of foreach
} //endif ! empty ( $related )
return ob_get_clean();
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
The above shortcode will get the IDs of the related posts from the specified pod and relationship field and then show the output in the HTML format that you shared from your content template.
Suppose that the pod name is "book" and the related field name is "related_books", then you can use this custom shortcode to show the related books, like this:
[custom_pod_related field="related_books" pod="book"]
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
It took me a while to realize but I think what bothers me about this is that it ought to be possible without custom code. Is this not possible with the built in features and shortcode?
Yes, I'm afraid so.
Toolset's post relationships can't be formed between the same post types and Pods offers this, but it has it's own methods/functions to extract the related post's data.
Here is the link to their official guide on the topic:
hidden link
It would be a good idea to also consult the Pods support team to confirm if there is a simpler shortcode available to get their related field data.