Problem:
The customer needed to filter posts in her directory by a custom taxonomy called Features, ensuring that only posts with all selected tags were displayed (using an AND operator instead of OR).
Solution:
We determined that Toolset Blocks does not natively support changing the operator from OR to AND for multiple select fields. As a workaround, we enabled legacy views and configured the custom search to use the AND operator. Additionally, we used custom code with the wpv_filter_query filter to change the operator to AND. The specific code was added to the theme's functions.php file, targeting the correct view_id:
add_filter('wpv_filter_query', 'custom_taxonomy_query_operator', 10, 3);
function custom_taxonomy_query_operator($query_args, $view_settings, $view_id) {
if ($view_id == 509) {
if (isset($query_args['tax_query'])) {
foreach ($query_args['tax_query'] as &$tax_query) {
if (isset($tax_query['operator']) && $tax_query['operator'] == 'IN') {
$tax_query['operator'] = 'AND';
}
}
}
}
return $query_args;
}
How can I limit the maximum total count of characters or lines in a multi-line field in a form?
Solution:
Use the following jQuery code to limit the number of lines in a multi-line field. This example sets a limit of 2 lines, but you can adjust this by changing the value of maxLines:
jQuery.noConflict();
(function($) {
$(document).ready(function() {
var maxLines = 2;
$('textarea').on('input', function() {
var textarea = $(this);
var lines = textarea.val().split('\n');
if (lines.length > maxLines) {
textarea.val(lines.slice(0, maxLines).join('\n'));
}
});
});
})(jQuery);