Re the conditional statements: Because for some horses that information is not available and the client does not want the layout showing up if there's no information to fill it in.
Regarding related posts: I was hoping there was a better way of showing the offspring than to try to connect post types. Because in order to connect posts, I would have to make different custom post types for each category of horse and that is far too cumbersome and time consuming, not to mention not particularly efficient when maintaining the site because a new post would have to be created every time a horse changed status - like a sale horse getting sold or a baby horse growing into an adult horse. It also would be an ugly layout because there would be one row for each category and if there is only one item per category it would look dumb. I was hoping there was an easier way to show filtered results. It seemed like we were getting close with the queries but it seems like there isn't a way to set a query to search for and match each horse with its offspring.
Hello,
Minesh is on vacation, I will take care of this thread.
I am little missing in this thread, for the question:
https://toolset.com/forums/topic/split-post-relationships-not-showing-on-the-front-end-filter-by-custom-field/#post-1550237
What I would like to do is be able to make a view where the dam field is matched to the corresponding horse page. Is there a way to do that?
I assume you are going to connect horse posts with other horse posts by using custom field "dam" value, which value is another horse post title.
If it is, you can try these:
1) Create a post view "related-dam-horse":
- Query horse posts
- Filter by:
Filter post title by a search term set by the View shortcode attribute: search. eg. [wpv-view name="view-name" search="search term"]
- In view's loop, display horse post information
2) In a single horse post, you can get the field "dam" value with shortcode:
[types field='dam'][/types]
Pass it to view's shortcode, for example:
[wpv-view name="related-dam-horse" search="[types field='dam'][/types]"]
It should be able to get related dam house post information.
More help:
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
I'm sorry but I still can't figure out how to properly set up the Query Filter. I thought I was getting it, but all the horses were showing up as offspring on every page. Can I give you the log in credentials so you can take a look?
I can get your test site credentials here:
https://toolset.com/forums/topic/split-post-relationships-not-showing-on-the-front-end-filter-by-custom-field/#post-1567495
And have done below modifications in your website:
1) Edit the content template:
hidden link
Change the shortcode in section "Offspring" as below:
[wpv-conditional if="( $(wpcf-dam) ne '')"][wpv-view name="related-dam-horse" search="[types field='dam'][/types]"][/wpv-conditional]
It will check if custom field "dam" isn't empty, then display the post view "related-dam-horse"
2) Edit the post view "related-dam-horse":
hidden link
Add a filter:
Filter post content and title by a search term set by the View shortcode attribute: search. eg. [wpv-view name="view-name" search="search term"]
To test the result which horse post with "Dam" field value:
Edit the horse post:
hidden link
in custom field "Dam", fill another horse post name: Amer Azhaar
Test it in front-end:
hidden link
I can see correct result in section "Offspring"
For other horse post without "Dam" field value, for example:
hidden link
Please check if it is what you want.
Unfortunately, that is not correct. For Desired Millicent, the offspring that should be showing are Waheed Al Azhaar RZ, Mistazah and Finneas RZ. For Mistazah the offspring showing should be Jassirah RZ. What you are showing is the dam that is the parent. I hope these graphic screen shots illustrate the relationship between parent & dam that I am trying to match in the offspring section.
Thanks for the details, I have done' below modifications in your website:
1) Edit the post view "related-dam-horse", in section "Query Filter", change the filter to:
Select items with field:
Dam is a string equal to VIEW_PARAM(dam)
2) Edit the content template "Template for Horse Details", change view's shortcode to:
[wpv-view name="related-dam-horse" dam="[wpv-post-title]"]
Test it in front-end:
hidden link
I can see three items in section "Offspring":
- WAHEED AL AZHAAR RZ
- MISTAZAH
- FINNEAS RZ
hidden link
Only one item in section "Offspring":
- JASSIRAH RZ
Please check if it is fixed.
More help:
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
Yes! Thank you!!!! That is exactly what I am looking for. And I would never have been able to figure that out on my own. So thank you very, very much!!!!
And just one last question - is there a way to hide that section completely if the horse doesn't have any offspring? Because it looks kind of dumb to have a neutered male with a section that says "Offspring", even if it gives the message that there are no matching posts.
Because eventually, what I'd really like to do with this is to have one post type called "Horses" with categories, instead of multiple post types (Stallions, For Sale, Horses) for all the different categories. That will be much less work - with one template and one view and an easy way to change the horse category when needed - instead of the clunky way I have it set up while I was still learning in this example site.
You can use CSS codes to hide it, for example:
1) Edit the content templet "Template for Horse Details"
hidden link
find and edit row "Offspring", add a CSS class: hide-on-empty
See screenshot hide-on-empty.JPG
2) Edit the post view "related-dam-horse"
hidden link
In section "Loop Editor", just after the text "No offspring were found for this horse.", add below CSS codes:
<style>.hide-on-empty{display:none;}</style>
Test it in front-end, for example:
hidden link
Great! Thank you so very much!
My issue is resolved now. Thank you!