I have created a View that displays information from my "Lodge" custom post types. Each Lodge has a custom field "Type". I want to be able to display the View on a page using a shortcode, but only include certain "Type" values when I display it. For instance, on one page I may want to display all Lodges of type 1, and on another page I may want to display only lodges that are type 2 or 3.
I know that I can use URL parameters to set the filters, but in this case, I don't have the ability to use URL parameters.
I know that there's the "[wpv-view]" shortcode, but it only has options for sorting the records, not filtering them. What I'm looking for is something like [wpv-view name="my-lodges" filters="type='1'"] or something like that. Is this possible?
Hello. Thank you for contacting the Toolset support.
The way you want to filter your view using the custom arguments is called filtering the view by shortcode attribute.
You should simply set your view to filter by shortcode argument by adding the related custom field query filter from the "Query Filter" section of the view.
- Navigate to "Query Filter" section of your view
- Click on the button "Add a filter"
- Select Type filed and add the query filter
- Select "Shortcode attribute" and given filter attribute name "filtertype" and save the filter
- Screenshot: hidden link
Add the view to filter by the values - For example:
// Filter the view by Type 1
[wpv-view name="my-lodges" filtertype="type-1"]
// Filter the view by Type 2
[wpv-view name="my-lodges" filtertype="type-2"]
Thanks Minesh, I was able to add shortcode attribute query filters to my view. However, the problem I' m now facing is that the shortcode attribute used for the query filter is itself contained in a custom field associated with the post where the shortcode will appear.
I need the contents of the field "province-state" to populate the shortcode attribute value. I tried adding this to the page:
The method you use seems correct but I need to check why its not working on your install.
Can you please send me temporary admin access details and problem URL where you added the "explore-page-lodge-grid" view?
*** 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.