Skip Navigation

[Resolved] View to display text, if no posts are returned from filter

This support ticket is created 2 years, 11 months ago. 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.

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 8 replies, has 3 voices.

Last updated by Minesh 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#2031239

Tell us what you are trying to do?

I have created a view that displays weather reports using the region taxonomy for the current day. However if no reports are made for the day, I would like there to be text that says “No reports for today (possibly dynamic date).” What can I add to the shortcode to display the text if there are no available weather reports?

Another issue with my view is that I would like the search bar and datepicker shown below the reports. Will this require two separate views? How would I display no reports until it is searched?

hidden link

Is there any documentation that you are following?
https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

Is there a similar example that we can see?
What is the link to your site?

#2031827

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting the Toolset support.

No need to have two views in order to place the search filters where you need them. Actually, you can't search a view using a search form from another view. The search form needs to be part of the view.

You can see all of the view settings by using the screen options button. Check this screenshot hidden link
The view has 3 editable sections:
- Search and Pagination
- Loop Editor
- Output Editor.

For your first question, you can customize what to display when no results are found in the Loop Editor section. The content needs to go inside the wpv-no-items-found shortcode. Check this screenshot hidden link

Regarding the placement of search form vs result sets, you can customize that at the Output Editor section. Check this screenshot hidden link
You can use your own HTML and shortcodes in all of the 3 sections.

Check all the available shortcodes for view here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/

#2036101

Hi Jamal,

Thanks for the information on the sections.

hidden link
hidden link

Currently using Divi code blocks to display the 2 taxonomy posts. In the gray sections, I'm trying to use [wpv-view name="current-weather-posts" wpvregion="pacific"] and [wpv-view name="current-weather-posts" wpvregion="Atlantic"] with the [wpv-filter-start hide="true"] to hide the search field and datepicker.

In the yellow section I would only like the search field and datepicker displayed, no posts until it is searched by viewer. As you can see, the post with a publish date of today is still displayed using the same view and shortcode [wpv-view name="current-weather-posts" ]

Not sure what I'm doing wrong.

Thanks in advance,
Leslie

#2037779

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Jamal is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

As I understand, you do not want to display any results under yellow section until the search if performed. If that is true, you will require to use the view's filter hook: wpv_filter_query

For example:

add_filter( 'wpv_filter_query', 'func_display_no_result_by_default', 10, 3 );
     function func_display_no_result_by_default( $query_args, $setting,$view_id ) {
    if($view_id == 99999) {

         if(!isset($_REQUEST['wpv_filter_submit'])) {
            $query_args['post__in'] = array(0);
        }
    }
    return $query_args;
}

Where:
- Please replace 9999 with your original view ID
- please adjust the filter code if required as per your requirement
- You can add the above code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#2041595

Thank you, Minesh. That custom code worked in hiding the results. While this code works, (Per Jamal - I would only need one view) so I need this same view to display the results (posts for the current date) in the gray section. What is the shortcode I need to achieve this outcome (please see reply for current shortcode used) ? Unless I would need to use a second view for the same post type, searching the posts not for the current date.
hidden link
hidden link

Please screenshot below for current search and pagination settings. When I press the “go” button, it is reloading the entire page and displaying results. Shouldn't my current settings avoid the entire page refresh? What can I changes can I make to avoid the entire page refreshing?
hidden link

Thank you,
Leslie

#2042251

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to know that solution I shared help you to resolve your issue.

I'm not sure how exactly you added your views and where or what different sections or pages.

If you can share problem URL and access details and tell me what exactly you want to display what and where that would help me to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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.

#2045989

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've added the view form and view result as given under:

[wpv-form-view name="lr-past-ww-posts" target_id="self"]
[wpv-view name="lr-past-ww-posts" view_display="layout"]

And within "Search and Pagination" section "JS Editor", I've added the following JS code to add "No Items found":
=> hidden link

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.layout (object) The jQuery object for the View layout wrapper
    
	*/
  
  if(jQuery(".js-wpv-view-layout li").length == 0){
    	jQuery(".js-wpv-view-layout").append("<li>No Items Found</li>")
  }
	
});

Can you please confirm it works as expected now.

#2047031

Hi Minesh,

I’m noticing some issues. The changes you made have avoided a page refresh when I view the page in a Chrome browser. However, when viewing the page in the Safari browser, the page refreshes.

Regardless of browser used:
1. It isn’t pulling the correct posts. Whether I search via keyword or date, I am still receiving a “no items found” message or is blank.
2. “No items found” is also being displayed under the “current activity” section (using Safari)
3. Any secondary searches will not display any results.

What other changes can be implemented to resolve the issue?

Thank you,
Leslie

#2047683

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The thing is that we have limited integration with Divi and we do not recommond to use ajax filters using divi as it may also result in losing styles etc..etc..

In addition to that, when you add the view as given under, as search form and search result, its not possible to use the ajax filters when using Divi.

[wpv-form-view name="lr-past-ww-posts" target_id="self"]
[wpv-view name="lr-past-ww-posts" view_display="layout"]

So, I've set the following view to reload when submit the search button rather using ajax:
=> hidden link

Also, I've added the following JS code within the "Search and Pagination" section "JS Editor":

jQuery(document).ready(function($){
  
  const urlParams = new URLSearchParams(window.location.search);
  var is_present = urlParams.has('wpv_post_search');
  const param_value = urlParams.get('wpv_post_search');
  

	if(is_present && param_value !=""  && jQuery("#wpv-view-layout-1300332 li").length == 0){
    	jQuery("#wpv-view-layout-1300332").append("<li>No Items Found</li>")
  	}
});

If I search with keyword storm I can see it returns correct results, two in this case and if I search using keyword abc it returns not result and if also displays the message "No Items Found" that is added using the above JS code. Can you please confirm it works at your end as well.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.