The example is involving both PHP and JS because you need the selection dynamic.
1. Create a Toolset Form, that features a Taxonomy Selector of select kind (in my example it is a DropDown single select)
2. Note down the Slug of your Taxonomy that is used in the Selector (in my case that is your-taxonomy-slug)
3. We create a custom shortcode to get the Term ID by Post ID. We add this code to the Theme's functions.php:
function ts_get_term_id_by_post_id( $atts = array(), $content = '' ) {
$atts = shortcode_atts( array(
'id' => '',
), $atts, 'get-term-id-by-post-id' );
foreach((get_the_terms($atts['id'], 'your-taxonomy-slug')) as $term) { return $term->term_id; }
}
add_shortcode( 'get-term-id-by-post-id', 'ts_get_term_id_by_post_id' );
We use WordPress ShortCode API as you can see, and this generates a ShortCode, which we can use later.
NOTE:
The above code only works if each post has ONE but no more term of the same taxonomy.
You must replace your-taxonomy-slug with the real slug of the taxonomy you use.
4. Insert a JS code like below in the Form's JS editor (just below the main drag and drop):
jQuery(document).ready(function($) {
var theTermHTML = document.getElementById("theTermID");
var theTermID = theTermHTML.innerHTML;
$("select[name^='your-taxonomy-slug[]'] option[value='"+theTermID+"']").attr("selected","selected");
});
You must replace your-taxonomy-slug with the real slug of the taxonomy you use.
5. Where you add the above Form (likely a View that lists all questions) you should (just before you add the Form) add this little HTML using our previously prepared ShortCode:
<div class="hidden" id="theTermID">[get-term-id-by-post-id id="[wpv-post-id]"]</div>
This will ensure, that the Term ID of the Post which should then be used for the form is actually added to the page.
It will not be visible as we have given it "hidden" class.
If your Website doesn't yet have it, you can add a CSS class for hidden in your Theme's CSS files, for example, like so:
.hidden {
display:none;
}
That's it.
Now, when you load the post (Review) where you have a lot of questions added (in a view) and each question has a reply form, that reply form will each have the same term selected, as the current Question of the current Review has.
This may sound a bit complicated, I suggest going thru above step by step and ask if you are not comfortable doing any of it, we can help with it.