Skip Navigation

[Resolved] How to hard-code filters into a shortcode when displaying a view?

This support ticket is created 5 years 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 ericE-4 4 years, 12 months ago.

Assisted by: Minesh.

Author
Posts
#1443533

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?

#1443841

Minesh
Supporter

Languages: English (English )

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

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"] 

Here is the related Doc:
=> https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

#1445161

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:

[wpv-view name="explore-page-lodge-grid" provstate="[types field='province-state' output='raw'][/types]"][/types]

but it doesn't work.

#1445673

Minesh
Supporter

Languages: English (English )

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

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.

#1446039

Minesh
Supporter

Languages: English (English )

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

As soon as I remove the following code (frontend filters) from the 'Search and Pagination' section:

<div class="form-group">
	<label for="prov-state">[wpml-string context="wpv-views"]Province/state[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-prov-state" url_param="prov-state"]
</div>
<div class="form-group">
	<label for="region">[wpml-string context="wpv-views"]Region[/wpml-string]</label>
	[wpv-control-postmeta field="wpcf-region" url_param="region"]
</div>

The shortcode attribute was not working becaues you have added the frontend filters for the same fields.

The view will start to filter by shortcode attribute as soon as you remove the above frontend filters and save the view. Can you please confirm?

#1447761

Thanks. I thought I needed that code in order for it to work.