Skip Navigation

[Resolved] Using a Shortcode in a filter for a view

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

Assisted by: Minesh.

Author
Posts
#2512529

My site uses Ticket Plus and the shortcode [ticketcount] to determine the remaining tickets.

I would like to add a boolean switch to my View (legacy) to allow the viewer to filter by "Show Sold Out" true/false that hids any items where the [ticketcount] <=0!

#2513649

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Toolset view offers the conditional shortcode [wpv-condition] that you can use to display conditional content. For example:

[wpv-conditional if="( '[ticketcount]' gt '0' )"]
Count:  [ticketcount]
[/wpv-conditional]

- Where above shortcode will display the Count: if [ticketcount] shortcode is greater than 0.
- please note that you will have to register the "ticketcount" shortcode name at:
=> Toolset -> Settings page and click the Front-end Content tab. There, simply add your shortcode to the Third-party shortcode arguments section.

More info:
- https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/#checking-custom-shortcodes

Can you please try to use that and check if that help you to resolve your issue.

#2513835
2022-12-12_12-26-48.png

Minesh, that is the code to add a conditional output and is not a "filter".

I am looking to add a filter to the view that only displays items returned in the search results that have [ticketcount] > 0. Ald adds a checkbox on the UX to allow viewers to toggle the visibility of these items.

#2513847

Minesh
Supporter

Languages: English (English )

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

Basically - you can add the frontend filter for custom fields, taxonomies. There is no way to add the frontend filter for the shortcode.

Can you please share problem URL where you added the said view and admin access details and let me review the current setup and check what possible workaround is possible and I can offer.

*** 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.

#2516137

Can you provide an example of the code that I would need to write to add a custom filter using the shortcode and linked to a UI element In the filters?

#2516175

Minesh
Supporter

Languages: English (English )

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

In general -you can add a "wpv_filter_query" hook and then try to add a custom query within it to get all IDs of posts where ticketcount is greater then 0 and later use the post__in argument to hook in the found post IDs that has ticket count greater than 0.

Here is the hook details:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Its hard to offer you exact custom code that should work without reviewing your current structure.

Here is the reference ticket where I shared related solution not the exactly the one that you want (you can build you own based on the following example) but might help you to understand how you can write "wpv_filter_query" filter:
=> https://toolset.com/forums/topic/custom-query-filter-with-multiple-conditions/page/2/#post-1912123

If you require further assistance then as requested please share problem URL and admin access details and from where I can get the totalcount.

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