so-widgets-bundle
so-widgets-bundle copied to clipboard
Blog Portfolio: If Taxonomies are selected, only show those as filter options
This is currently possible using https://github.com/siteorigin/so-widgets-bundle/pull/2029, but it would be better to alter how the Portfolio template works to allow for this out of the box. Here's a snippet I previously wrote to do this:
add_filter( 'siteorigin_widgets_blog_portfolio_taxonomy', function( $taxonomy, $instance, $post_type ) {
$posts = wp_parse_args( siteorigin_widget_post_selector_process_query( $instance['posts'] ) );
if (
empty( $posts['tax_query'] ) ||
! is_array( $posts['tax_query'] )
) {
return $taxonomy;
}
$valid_taxonomies = array();
foreach ( $posts['tax_query'] as $tax_query ) {
if ( isset( $tax_query['terms'] ) ) {
$tax_query['slug'] = sanitize_title( $tax_query['terms'] );
$valid_taxonomies[] = (object) $tax_query;
}
}
return $valid_taxonomies;
}, 10, 3 );