This support ticket is created hace 7 años, 5 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Hi.
I have a custom post type with a category structure, like:
Books
- Thrillers
- Sci-Fi
- Romance
All my books are set to both category "Books" and the correct subcategory.
When i view any of the books in the subcategory i want to display all related books in that subcategory in a list beside the book info.
I have a View with Taxonomy filter of that category.
But the problem is:
My Related Posts show things from "Books", which is not what i want.
If i view a "Sci-Fi", i only want to show other books in that subcategory.
What are the correct settings for this?.
There aren't any correct settings for this because the taxonomy filter used to qualify which posts are returned is comparing the categories of each post against the post where the view is added, so a SciFi book will match all books because both have the category book, i.e. it is expected behaviour.
Note the key part here is the "[operator] => IN" which is an OR operator (if the posts have either the Book or SciFi categories, for example. You need to change that to AND, so that posts will only match if they have both the Book and SciFi categories.
Hi.
Thank you for your reply, i will try that.
I was really hoping for an easier solution (with less code...).
So:
What's your opinion about all those "wordpress related posts plugins".
Have you any experience with any of them? And would one of these possibly solve this specific problem?
Any you would recommend? And any that works well with Toolset?
A related posts plugin seems like overkill in this case.
If you want to avoid any coding, what I would do is, instead of having one hierarchical taxonomy, to split it into two taxonomies.
So if you top level taxonomy has terms books and... what else... magazines, DVDs etc., and your lower tier terms are for SciFi, Romance etc. then I would make a taxonomy called "media" which has terms "books, magazines, DVDs, whatever", and a separate taxonomy, let's say, "genre" with "SciFi, Romance, Crime" etc.
Then your view for related books in the same genre would have two taxonomy filters, one for media, one for genre.
Hi.
You mean "Non-Hierarchical Taxonomy" (tags)?
I already have hundreds of Books in the site, so i want to change as little as possible. I also have about 100 subcategories of these Books.
You wrote:
"let's say, "genre" with "SciFi, Romance, Crime" etc."
But that won't work, will it?
I mean, when i'm viewing a "Sci_Fi" book, won't the "Related Posts" show things from "Romance" and "Crime" too?
I want only related "Sci-Fi" books to show up.
It's a lot of work, but won't i have to create 100 tags?
I really hope there is an easier solution.
Hi again.
Can't we do this with Views "Conditional statements", somehow?
All i really want is:
In my "View Show Related Books", i want a conditional statement that says:
- Ignore all "Books". That is, the parent category
- Just show the Books in the current subcategory, like "Sci-Fi".
The term 'hierarchical' to distinguish between a category-type taxonomy and a tag-type taxonomy is not very helpful here, I was suggesting continuing using categories but making the hierarchy just one level deep.
The problem generally, and specifically for your last suggestion, is that all books have the books category in common, and as long as that's the case, all books will show up in a query that looks for posts with matching categories.
If you don't actually need the Books category (because there is no magazines, no DVD, no whatever other top level category) then just delete it. Then SciFi books will have the same category as other SciFi books but not as Crime books. I don't know whether that is an option, I don't know if you have sections which depend on the presence of the Books category.
I'll see if I can set up a test site with a code snippet to get this working as I described initially, and I'll let you know what I come up with.
Here is a small code snippet that should do the job.
You will need to edit the view id accordingly, and, note that I wrote this with a plain vanilla view in mind that just uses a taxonomy filter like so: "Select posts with taxonomy: Categories the same as the current post in the loop".
If you are doing something more complex then this might not work.