Hello.
I want to display inline related posts based on the child taxonomy term. So, a post tagged with the taxonomy terms Europe, England, London will display posts about London, if these do not exist display posts about England and if these do not exist display posts about Europe.
I've been trying to tweak this but without success. The posts are displaying, but they're not a close match. Sometimes I get posts about Greece in a London article, just because Greece is a child of Europe.
I have two views: a parent view and a child view.
In the parent view I have the Query Filter "set by the page where this view is shown" AND some categories. and
In the Child view I have "Set by the current archive page".
How can I do this, so that the related articles are accurate?
Many thanks.
Hello,
It is possible with a nested view, for example:
1) Grandparent taxonomy view:
- Query categories terms
- Filter by:
Taxonomy is set by the page where this View is inserted
- In view's loop, display below parent taxomomy view.
2) Parent taxonomy view:
- Query categories terms
- Filter by:
Select taxonomy terms whose parent is the value set by the parent view.
- In view's loop, display below child post view.
3) Child post view
- Query posts of your custom post types
- Filter by:
Select posts with taxonomy:
Categories set by the parent Taxonomy View
- In view's loop, display post information
Hi Luo,
Thanks for your reply. I've tried your instructions, but it doesn't work. It still outputs completely unrelated articles.
I've attached the screenshots of the 3 views.
Could you please have a look? Thanks.
I have tried it in my localhost with a fresh WP installation + the latest version of Toolset plugins, it works fine.
please try these in your website:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/
2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, deactivate all custom PHP/JS code snippets, and test again
3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/
4) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL and view URLs, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/
Hi,
Thank you for sharing these details.
Luo is on holiday today and will be able to follow-up on this once he is back tomorrow.
Thank you for your patience.
regards,
Waqar
Thanks for the details, I can download the file, will update here if find anything
Here are what I found, the issue your mentioned above is easier than I thought, it needs only two views: one taxonomy view + one child post view
1) Parent taxonomy view:
- Query Viagens taxonomy terms
- Filter by:
Taxonomy is set by the page where this View is inserted
- Ordering:
Order by Post count Aescending
- Limit and Offset :
Display only 1 item
In your case, since parent term will always have more posts than child terms, so you will be able to get the sub term in the result
- In view's loop, display below child post view shortcode:
[wpv-view name="related-articles-toolset-child"]
2) Then display above parent taxonomy view shortcode in your content template "Notícias de viagem template"
Hi Luo,
Thanks for that.
So I've been trying and I think it's close to perfect, but I'm also adding the Categories to the Mix, so I can exclude some categories I don't want to feature in the related posts block.
However, in some cases there are posts where no Taxonomy terms are selected, only Categories. And in this case, sometimes I'm getting the page where the view is displaying as a Related Article.
The settings I have at the moment are the ones you told me in the Parent View and in the Child View I've got the Query: "Set by the Parent Taxonomy View" AND the Categories I'm excluding.
Basically, it would be great if the view wouldn't display if there no items to display. But definitely not displaying the post where is inserted.
I would also like to confirm that the settings (as they are) would display posts of the Parent term if no Child Term posts exist?
UPDATE: The settings I have at the moment are causing timeouts in the server, it seems it enters in a infinite loop.
Example: if the view is inserted in page/post about Brasil AND the only existent posts are tagged with "offers" category (which is one of the excluded categories in the query filter), then the post or page breaks.
How can I tweak it?
Thanks.
Q1) Basically, it would be great if the view wouldn't display if there no items to display. But definitely not displaying the post where is inserted.
You can use [wpv-conditional] shortcode to check if there current page/post has assigned with any Viagens term, then output different as you want, for example:
[wpv-conditional if="('[wpv-post-taxonomy type='viagens ' format='slug' ]' ne '' )"]
Terms assigned to current post/page
[/wpv-conditional]
[wpv-conditional if="('[wpv-post-taxonomy type='viagens ' format='slug' ]' eq '' )"]
No terms assigned to current post/page
[/wpv-conditional]
More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/displaying-taxonomies-conditionally/
Thanks. I've got a few questions about how to achieve this.
1 - What I want to achieve: display primarily related posts of the child taxonomy where the view is inserted AND exclude some categories (I'm using the query for this at the moment). IF no other posts of the Child Taxonomy are available, then display posts of the Parent Taxonomy. IF no posts of the parent Taxonomy are available, then displays posts of the tagged WP Category. IF no other posts exist of the same category where the view is inserted, then display nothing.
2 - Do I add the conditional to the Parent or Child View?
3- Do I add the condition to the [wpv-items-found] loop or to the [wpv-no-items-found] loop?
4 - Some posts are NOT tagged with Taxonomy terms, ONLY with categories. Will number 1 solution work for these situations?
Thanks.
I am not sure why do you need such kind of complicate conditions and logic, is there any special reason?
In your case, you might try custom codes, for example,
1) create a post view:
- Query articles posts
- In view's loop display articles post information
2) Setup custom PHP codes, use filter hook wpv_filter_query to trigger a PHP function:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
3) In above PHP function, get the "viagens" taxonomy terms assigned to current post:
https://developer.wordpress.org/reference/functions/get_object_taxonomies/
And check them according to your conditions and logic, then get the related post IDs
https://developer.wordpress.org/reference/classes/wp_query/
Then use post IDs as parameter "post__in" of view's query, for example:
...
$query_args['post__in'] = array(123, 456, 789);
return $query_args;
...
Your solution seems like a very complicated way of doing this.
I don't think what I need is very complicated. All I need is to always display a related article within the posts. It doesn't make sense for a reader to be reading an article about London and being shown related articles about Barcelona. If someone is reading a post about London it's great to see other posts about London or in alternative about England which is the parent term or Europe, the grandparent.
That's why I asked for the view to display the related articles for the child taxonomy. But I don't want to show articles of certain categories because they don't make sense. Example: I have travel offers that are time sensitive and doesn't make sense to display it within the posts. So, I have to use the "AND" clause in the query to exclude a couple of categories.
But some posts are only tagged with Categories. If I've got a post about "tourism" in general I can't tag it with a specific geographic taxonomy term (country, city, etc). Therefore, this post is only tagged with the category "Travel Tips". So, it would be great to display related articles of the same category.
Does it make sense?
Can this be achieved with views?
Thanks.
I guess one way to achieve this would be to create a third view and insert the 3rd view shortcode into the [wpv-no-items-found] loop in the Parent View or the Child View. This way I could use other query arguments.
1 - What is the best way (view settings) to display related articles of, let's say as an example: seeing a related post about Brasil if I'm reading a post about Colombia (Because these are both children of South America)?
2 - Is there a way to insert dynamically a View after "nth" paragraph?
Thanks.
Yes, you can try put the third view shortcode into [wpv-no-items-found] ... [/wpv-no-items-found], but it might conduct some unexpected performance problem, since you are using three level nested views.
for the new questions:
q1) let's say as an example: seeing a related post about Brasil if I'm reading a post about Colombia (Because these are both children of South America)?
There isn't such kind of built-in feature within Toolset, you might consider custom codes, for example:
create a custom shortcode:
1. get current post taxonomy term "Brasil"
https://developer.wordpress.org/reference/functions/get_object_taxonomies/
2. get the parent term "South America" by above term "Brasil":
https://developer.wordpress.org/reference/functions/get_ancestors/
3. get all child terms of "South America"
https://developer.wordpress.org/reference/functions/get_terms/
4. then get posts by above terms
https://developer.wordpress.org/reference/classes/wp_query/
Q2) Is there a way to insert dynamically a View after "nth" paragraph?
Same as above, there isn't such kind of built-in feature within Toolset, you might consider custom codes, for example, use the_content filter hook to trigger a PHP function, find the nth paragraph, then render the view's shortcode
More help:
https://developer.wordpress.org/reference/hooks/the_content/
And according to our support policy, we don't provide custom codes support, you can check it with our Toolset Consultants:
https://toolset.com/contractors/
Ok. I understand. I'll try to find another way for not found articles.
If I insert a view 3 times along a post, is there a way for the system to detect that there is more than one view on the page and not show the same related post more than once?
I know I can display more than one item via the query, but that will display it side by side.
Thanks.