I noticed that the problem was related that one custom field was a taxonomy, so, as I was using the archive page for that custom post type, I only needed to filter the query looking for the date limits.
$fecha_actual = current_time('Ymt'); //t regresa el ultimo día del mes
$fecha_anterior = date('Ymd', strtotime("first day of last month"));
add_action('pre_get_posts', 'my_pre_get_posts', 10, 1);
function my_pre_get_posts( $query ) {
global $fecha_actual, $fecha_anterior;
if( is_admin() ) {
return;
}
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'producto' && is_archive()) {
$meta_query = $query->get('meta_query');
if( !empty($_GET[ 'marca' ]) ) {
$meta_query[] = array(
array(
'key' => 'fecha',
'value' => array($fecha_anterior, $fecha_actual),
'compare' => 'BETWEEN',
'type' => 'DATE'
)
);
}
$query->set('meta_query', $meta_query);
$query->set('meta_key','fecha');
$query->set('orderby','meta_value_num');
$query->set('order','ASC');
}
}