Ok it sounds like it will be best to make the options dynamic since you will have a lot of them and they are not all defined yet. No need to worry about providing them right now, I will set it up so that it will work as your options for subcategories grow.
1. Create at least one main category and a few of its subcategories manually for now.
2. Create at least one post for each of the subcategories you created, so that each subcategory term will be associated with at least one post.
3. Create a View of your taxonomy. In the Query Filter section, filter by Taxonomy parent.
4. Select the top-level category from step 1 as the parent filter.
5. Add the following code to your theme's functions.php file:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 10, 3);
function prefix_clean_view_output( $out, $id ) {
if ( $id == '12345' ) { //Please adjust to your Views ID
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
} else {
$start = strpos( $out, '>' );
if ( $start !== false) {
$out = substr( $out, $start + 1 );
$end = strpos( $out, '<' );
$out = trim(substr( $out, 0, $end ));
}
}
}
return $out;
}
- Replace '12345' with the numeric ID of the View you just created. You can find that in the URL when you edit your View.
- Place the View on some custom page to test it out. You should see results that look like this:
{"value":"slug-1","label":"Term 1"} ,{"value":"slug-2","label":"Term 2"} ,{"value":"slug-3","label":"Term 3"}
Let me know once you have this working and we can continue. Otherwise if you get stuck let me know and I can lend a hand.
- edited to fix code error