Home › Toolset Professional Support › [Resolved] Manually add some related posts
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 |
---|---|---|---|---|---|---|
- | 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)
This topic contains 22 replies, has 3 voices.
Last updated by dominiqueM-3 2 years, 8 months ago.
Assisted by: Shane.
Tell us what you are trying to do?
Hello,
For a blog-type site, I would like to allow the webmaster to manually associate each post with other posts that share the same theme.
I read in the Toolset forum that it is not possible to create relationships between posts of the same content type.
Especially if the posts are native WordPress posts.
Apparently there would be a solution using tags, but it seems quite cumbersome to me to implement.
Another solution would be to create a custom field for posts, in which the webmaster could indicate the ID of related articles. Then create a view to list the articles referenced in this custom field (title, featured image, etc.).
Unfortunately I have not found a detailed explanation to implement this method and I will need some help.
Thank you
Hello. Thank you for contacting the Toolset support.
I read in the Toolset forum that it is not possible to create relationships between posts of the same content type.
==>
Yes, that is true that we do not offer the self join relationship for any post type including standard post types and custom post types.
Another solution would be to create a custom field for posts, in which the webmaster could indicate the ID of related articles. Then create a view to list the articles referenced in this custom field (title, featured image, etc.).
==>
If you agree to use to add a custom field that holds the IDs of those related posts, then you should add a custom field and set it to be repeating field so that you can add multiple values to it.
I'm not sure yet where exactly you stuck, if you setup a repeating field and add your related post IDs to it and add a view and tell me where exactly you require help I would be happy to help.
Hello Minesh,
Thank you for your reply.
In fact I don't really know how to build the view and use the IDs of related articles to display their title, their featured image and their url.
Thank you
Here is the information about how you can create a view (Block mode):
- https://toolset.com/course-lesson/creating-a-view/
But as you want filter the results with the custom field values, you will have to use the Classic views. You can enable the classic view by following the following doc:
=> https://toolset.com/course-lesson/enabling-legacy-version-of-toolset-views/
Then, you should create a view from: Toolset => Views and add your view and within the "Query Filter" section you should add your custom field filter and add it to filter by shortcode attribute:
=> https://toolset.com/documentation/user-guides/views/filtering-views-by-custom-fields/
And then you should add your view to your desired page/post/content template and filter it with shortcode attribute.
I suggest you first setup the structure and then let me know if you need any help.
More info:
=> https://toolset.com/documentation/legacy-features/views-plugin/
Minesh,
I tried to prepare the elements.
- a repeatable custom field in which to insert the IDs of related articles
- a view in classic mode
- a content template
When I insert my view in the content template, in the popup, there is a Query filters tab where you can enter a value.
I don't really know what to put since I want the IDs of the custom field to be used.
For now, the shortcode of my view is [wpv-view name="insight-related-posts-test2" relatedid="" cached="off"]
So far I can't get the desired result.
Can you please share problem URL where you want to display the related posts and admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've changed the query filter you added to your view as you can see with the following screenshot: hidden link
=> hidden link
On the content template, I've added the view you created above I've removed your existing view form the content template and added the above view using the "Fields and Text" block as given under to the right sidebar:
=> hidden link
[wpv-view name="insight-related-posts-test2" relatedid="[types field='insight-related-post-id' separator=','][/types]"]
Can you please confirm it works as expected:
=> hidden link
Minesh,
Sorry but the sidebar where related posts should display is empty for me.
I can see the two posts, can you please clear browser cache:
=> hidden link
Clearing the cache brings back sidebar posts.
What about the 2nd example post:
hidden link
For this one only one related article is assigned (id: 52).
However I can see 2 posts in the sidebar.
With your view:
=> hidden link
I've checked the setting "Query Options" setting " Don't include current page in query result" and I can see its working as expected.
I'm not sure.
I created a third post in the Insights category to test.
This post has the ID 167.
I then edited this post which has the ID 52:
hidden link
I assigned ID 50 and 167 as related posts ID.
In the View I can only see the post with ID 167. Not the one with ID 52.
I've added the following "wpv_filter_query" code to "Custom Code" section offered by Toolset:
=> hidden link
add_filter( 'wpv_filter_query', 'func_disp_related_posts_view', 10, 3 ); function func_disp_related_posts_view($query_args, $setting, $views_id) { global $post; if($views_id == 116) { $related_ids = get_post_meta($post->ID,'wpcf-insight-related-post-id'); if(!empty($related_ids)) { $query_args['post__in'] = $related_ids; }else{ $query_args['post__in'] = array(0); } } return $query_args; }
I've also removed the custom field "Query Filter" added for your custom field from your view's query filter section:
=> hidden link
Also, to your content template, the view is called as given under:
=> hidden link
[wpv-view name="insight-related-posts-test2" cached="off"]
I can see now correct results on the following pages:
- hidden link
- hidden link
Can you please confirm it works as expected.
Hello Minesh,
Many thanks for your change.
That said, it seems that my request goes beyond the nocode argument proposed by Toolset 😉
Anyway, it works the way I want it to.
I would like to address the subject of the order of articles in relation. Can I do this in this forum topic or would you rather I open a new topic.
Thank you
What if you try to set order from "Ordering" section of your view to your custom field.
=> hidden link