This snippet hides the container which has the vx postfeed widget if there are no related posts displayed.
JS Code SnippetOn the page you want this to appear, add an HTML widget (FREE) and paste the code in there. Be sure to have < script> before your code and after the code if it isn't already inserted above.
Instructions
You can use free elementor html widget to use this snippet. Don't forget to add "related-places" css class to the container which have the postfeed widget. You can change the css class as you need but don't forget to change it in the js code snippet.
<script> document.addEventListener('DOMContentLoaded', function() { setTimeout(function() { // Find the container with the "related-places" class const relatedPlacesContainer = document.querySelector('.related-places');
if (relatedPlacesContainer) { // Find the post feed widget inside the container const postFeedWidget = relatedPlacesContainer.querySelector('.elementor-widget-ts-post-feed');
if (postFeedWidget) { // Check if the post feed grid is empty (has no child elements besides the no-results message) const feedGrid = postFeedWidget.querySelector('.post-feed-grid'); const noResultsElement = postFeedWidget.querySelector('.ts-no-posts');
// Check if the feed is truly empty - both conditions must be true: // 1. The no-results element must exist // 2. The feed grid must have no direct children OR only have the no-results class if (noResultsElement && (feedGrid.children.length === 0 || (feedGrid.classList.contains('post-feed-no-results') && !feedGrid.querySelector(':scope > *')))) { // Hide the entire container relatedPlacesContainer.style.display = 'none'; } } } }, 700); // Increased delay to ensure content is fully loaded }); </script>