Skip Navigation

[Resolved] Using total count of unfiltered posts as conditional: if [wpv-found-count] < ALL

This support ticket is created 5 years, 8 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 5 replies, has 2 voices.

Last updated by BD 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1222986

BD

I have a CPT ('Businesses') with an associated taxonomy ('Business Category'). There are 152 Businesses listed in total.

I have created a view that lists Businesses using a parametric search filter that filters by the associated Business Category.

When the page is first loaded, the default_label for the wpv-control-post-taxonomy is 'Select a Category', which lists all 152 businesses.

I would like to hide the list of businesses until a Business Category is selected from the dropdown list.

I would therefore like to be able to create a conditional that uses the total number of Businesses (unfiltered) and only displays the results if the number is less than 'ALL' or if the the default_label is selected. Is this possible?

I have managed to do this by hard-coding the number (152) but obviously this is going to be a dynamic number:

[wpv-conditional if="( '[wpv-found-count]' lt '152' )"]
// display results
[/wpv-conditional]
#1222988

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - To restrict the search results items on search result page you need to use wpv_filter_query hook.

For example - add following code to your current theme's functions.php file
OR
"Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_filter( 'wpv_filter_query', 'func_disp_empty_view', 10, 3 );
function func_disp_empty_view($query, $setting, $views_id) {
    if($views_id == 9999)
    {
        if( !isset($_GET['wpv_view_count'])){
            $query_args['post__in'] = array(0);
        }
    }
    return $query;
}

Where:
- Please replace 9999 with your view ID.

More info:
=> https://toolset.com/documentation/programmer-reference/views-filters/wpv_filter_query/

#1222994

BD

Thank you Minesh. However, this doesn't seem to help.

I think that all I need is to be able to create a custom shortcode that returns the total number businesses that I can then use in the conditional statement - for example:

[wpv-conditional if="( '[wpv-found-count]' lt '[custom-shortcode-that-returns-total-number-of-unfiltered-posts]' )"]
// display results
[/wpv-conditional]

I don't want to restrict the number of businesses listed - I just want to hide the results until a term is selected from the dropdown.

Are you able to help me with the php for that shortcode? Many thanks

#1222995

Minesh
Supporter

Languages: English (English )

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

I understand your problem - there is not need to write shortcode, I think we can achieve this using the view's filter "wpv_filter_query" I shared.

Can you share problem URL and access details that will help me to guide you in the right direction.

I have set the next reply to private which means only you and I have access to it.

#1223036

Minesh
Supporter

Languages: English (English )

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

well - based on your structure I've another idea.

I've used the following conditional statement:

[wpv-conditional if="( '[wpv-search-term param='wpv-local-info-category']' ne '')"]
 [wpv-view name="essential-guide-categories" order="asc"]
<h4>[wpv-post-title]</h4><p>[wpv-conditional if="( $(wpcf-local-address) ne '' )"][types field='local-address' output='raw'][/types]<br>[/wpv-conditional][wpv-conditional if="( $(wpcf-local-telephone-number) ne '' )"]Tel: [types field='local-telephone-number' output='raw'][/types]<br>[/wpv-conditional][wpv-conditional if="( $(wpcf-local-email-address) ne '' )"]Email: <a href="mailto:[types field='local-email-address' output='raw'][/types]">[types field='local-email-address' output='raw'][/types]</a><br>[/wpv-conditional][wpv-conditional if="( $(wpcf-local-website) ne '' )"]<a href="[types field='local-website' output='raw'][/types]" target='_blank'>Visit Website</a>[/wpv-conditional]</p>
[/wpv-conditional]
 

I think this will serve your purpose. Can you please confirm it works as per your expectation.

More info:
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-search-term

#1223066

BD

Fabulous - that works perfectly, thank you Minesh.

Nick