Tell us what you are trying to do?
Pass a term-slug as a parameter on the page URL.
Detect and load the term object from the term-slug
While the taxonomy filters provides the option to select Taxonomy Term.
This only provides the ability to select a URL parameter that only evaluates the Term ID.
Not the term title or term-slug.
Is there any documentation that you are following?
No.
Is there a similar example that we can see?
What is the link to your site?
currently in dev.
Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and in a view that lists taxonomy terms, query filter only allows URL parameter filtering, based on the term ID.
( example screenshot: hidden link )
You're welcome to submit this as a feature request at:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
For a now a workaround can be to use "wpv_filter_taxonomy_query" filter instead, to add a filter by term's slug:
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query )
add_filter( 'wpv_filter_taxonomy_query', 'prefix_modify_tax_query', 10, 3 );
function prefix_modify_tax_query( $tax_query_settings, $view_settings, $view_id ) {
if ( ($view_id == 123) && (!empty ($_GET['term-slug'])) ) {
$view_settings['slug'] = $_GET['term-slug'];
}
return $view_settings;
}
As a result, in your taxonomy view with ID "123", results will be filtered based on the term slug passed in the URL parameter "term-slug".
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks Waqar,
the strategy you proposed helped me in outlining a design solution.
I ended up creating a custom shortcode that parses the url, searches for the term object by term-slug and returns the term ID. I pass this ID to the view shortcode as an attribute that filters the view results.
I added this level of abstraction because I need the ability for the admin/content creator to duplicate the view and change content selection without having to change any other properties. This allows for them to duplicate the view, customize it to target a specific taxonomy of terms and embed it into a page using a shortcode.
The view renders the body of the page, multiple term values (and custom fields attached to the term) while calling a secondary child view that lists multiple content types tagged with the specific term.
I had to register both shortcodes in Toolset > Settings > Frontend content > 3rd party shortcode arguments to allow me to "stack" shortcodes.
add_shortcode('gettermidbyslug', 'gettermidbyslug_shortcode');
function gettermidbyslug_shortcode($atts, $content = null, $tag = '') {
$atts = array_change_key_case((array)$atts, CASE_LOWER);
$param = in_array('param', $atts['']) ? $atts['param'] : 'categoryterm';
$termSlug = $_GET[$param];
$slugID = "0";
$termObj = "";
if (!empty($termSlug)) {
$taxonomies = get_taxonomies();
foreach ($taxonomies as $tax_type_key => $taxonomy) {
// If term object is returned, break out of loop. (Returns false if there's no object);
if ($termObj = get_term_by('slug', $termSlug, $taxonomy)) {
break;
} else {
// Term not found.
}
}
if (is_object($termObj)) {
if (property_exists($termObj, 'term_id')) {
$slugID = (string)$termObj->term_id;
}
}
}
return $slugID;
}
I then call the main index rendering view and pass the TermID.
[wpv-view name="landingpage-termindex-view" termid="[gettermidbyslug param="categoryterm"]"]
So now admin/content creators can duplicate the term index view and customize it based on content selection. Now to add conditional sub-templates for each content type (articles vs pages vs posts).