so-widgets-bundle icon indicating copy to clipboard operation
so-widgets-bundle copied to clipboard

Blog Portfolio: If Taxonomies are selected, only show those as filter options

Open AlexGStapleton opened this issue 1 year ago • 0 comments

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 );

AlexGStapleton avatar Sep 11 '24 23:09 AlexGStapleton