//***
add_filter('mdf_custom_shortcode_query_args', 'mdf_custom_shortcode_query_args', 10, 2);
function mdf_custom_shortcode_query_args($args, $custom_id)
{
$and_tax_relation = array('post_tag');
//https://codex.wordpress.org/WordPress_Taxonomy
if ($custom_id == '777')
{
$args['tax_query'] = mdf_modify_tax_query($args['tax_query'], $and_tax_relation);
//add_filter('mdf_dyn_tax_recount_args', 'mdf_dyn_tax_recount_args', 10, 1);
}
return $args;
}
//*** for dynamic recount
add_filter('mdf_dyn_tax_recount_args', 'mdf_dyn_tax_recount_args', 10, 1);
function mdf_dyn_tax_recount_args($tax_query_array)
{
$and_tax_relation = array('post_tag');
return mdf_modify_tax_query($tax_query_array, $and_tax_relation);
}
//logic of AND relations in taxonomies
function mdf_modify_tax_query($tax_query_array, $and_tax_relation)
{
if (!empty($tax_query_array))
{
foreach ($tax_query_array as $key => $value)
{
if (isset($value['taxonomy']))
{
if (in_array($value['taxonomy'], $and_tax_relation))
{
$tag_terms = $tax_query_array[$key]['terms'];
if (!empty($tag_terms))
{
$tag_terms_tpl = $tax_query_array[$key];
$tag_terms_tpl['terms'] = array();
unset($tax_query_array[$key]);
foreach ($tag_terms as $term_id)
{
$tag_terms_tpl['terms'] = array($term_id);
$tax_query_array[] = $tag_terms_tpl;
}
}
}
}
}
}
return $tax_query_array;
}