Home › Toolset Professional Support › [Resolved] Exporting 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 |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
This topic contains 20 replies, has 2 voices.
Last updated by simchaH 2 years, 10 months ago.
Assisted by: Minesh.
Hi,
I am trying to hide a parent view only if the nested view is empty. I saw this thread and attempted implementing it, the CSS is hiding the views, but the jQuery mentioned is not "reinstating" them again. I feel like it is some simple syntax I am missing. Would you be able to take a quick look and let me know if there is something I'm missing? The only thing I changed from the snippet in the pasted below thread is the $parent-slug- I changed it to the actual slug.
https://toolset.com/forums/topic/hide-parent-view-if-child-view-is-empty/
Thanks!
Hello. Thank you for contacting the Toolset support.
What if you try to add the javascript code as:
jQuery('.results-container-[wpv-post-id item="@relationship-slug.parent"]').css('display', 'block');
where:
- Replace "relationship-slug" with your original post relationship slug.
Hi,
Thanks for your tip- though it doesn't seem to be working. I feel like I might be putting in the relationship slug incorrectly. Does it make a difference that I have 2 nested views inside the parent/main view? I added the script to both of the children/nested views. For the relationship slug, does that have to be a different slug for each of the nested views?
Thanks!
Can you please share problem URL 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 and FTP) 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 see you added the display none to top parent view.
Can you please share URL or steps that I should follow so that I should be able to see the no result for the nested view and use it as test case to hide the parent view.
Sure, the URL is dyd.afullsentence.com/dy-directory
Underneath the map is where the loop generally shows up. Now there is nothing because of the display none.
I went into the two nested views, and I added a <script> with the jQuery inside it. See the screenshot attached where I added it in to the loop editor of one of the nested views (I added the same thing into both nested views).
Let me know if you need anything else,
Simcha
Yes, I understand that but what I want is a case when you want to display the result and when you want to hide the result.
Can you please share that?
Okay, got it. Here you go:
I want to display the result of the main/parent view ONLY when there is something in the nested view - particularly the nested shiurim view. So when the nested shiurim view is empty for any specific parent view, I want it hidden.
To elaborate so you understand clearly, the parent view are the locations on the map. The nested view are speeches that take place in those locations. I only want to display a location where there actually are speeches taking place. If a location doesn't contain a speech, I want it to be hidden from visitors of the site.
Thanks
Rather using that tricky JS script I've another workaround.
I've added the following filter code to "Custom Code" section offered by Toolset within the code snippet "toolset-custom-code":
=> hidden link
add_filter( 'wpv_filter_query_post_process', 'func_filter_child_none_post', 10, 3 ); function func_filter_child_none_post( $query, $view_settings, $view_id ) { if ($view_id==1152 and !empty( $query->posts ) ) { $all_posts = $query->posts; foreach($query->posts as $k=>$v): $parent_ids = toolset_get_related_posts( $v->ID, 'shiur-location-to-shiur', 'parent', 1000000,0, array(), 'post_id', 'child' ); if(empty($parent_ids)){ unset($all_posts[$k]); } endforeach; $query->posts = $all_posts; $query->found_posts = count($all_posts); // modify the count of found posts $query->post_count = count($all_posts); // modify the count of displayed posts } return $query; }
Can you please confirm it works as expected: hidden link
More info:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Thanks for the quick response and all the help Minesh. It doesn't seem to be working on my end, the whole page is blank expect for the header.
I deleted all the old code I put in (the jQuery and the CSS display none) and I left your snipper as is. Can you take another look?
Thanks so much
Can you please check now. I've adjusted the if condition within the filter hook I shared as given under:
if ($view_id==1152 and isset($_GET['wpv_view_count'])) {
Can you please check and let me know if it works as expected.
Thanks Minesh,
The view is showing up now, but the filter still doesn't seem to be working. When I scroll down I still see locations without shiurim inside of them. Also I think something in the code is making the input text search bar not work- when I type in a name of a place in the search bar above the map and I hit the "search" button, it just goes blank.
Thanks,
Sim
So that is what I'm asking can you please share few test case that I should use like what value I use for what filter and perform search and what is your expected result with that test case and what should be now. You should share two test case with which you want result and another one for which you do not want to display the result.
Even if I don't use any of the filters and I scroll down the page to view all locations (all posts), I never want to see a location without a shiur (nested view) inside, no matter what.
That is the main thing I am trying to accomplish. Do not display any location that has an empty nested-shiurim view.
I have attached an image where I did not click on any of the filter options and simply scrolled down the page. There you see the middle location says "No Shiurim at this Location. Add one here" - that means there is no nested view, which means that location should be hidden, always no matter what. The other two in the image that I have surrounded in red square, those accordion style dropboxes in the main view location, that is the nested view shiur, and every location that has one of those shiurim inside, that should always be displayed.
Using the filters should just work the same way. If I enter a name of a location (the first filter in the search bar), it should only give back locations that have this nested view (called "shiur") inside of it.
If someone searches for a location and we actually have the location listed in the backend, but it does not have any shiur attached to it, I don't want it being displayed to the user even though they searched for it.
Does this clarify things?
I forgot to attach the image, here you go.