Код: Выделить всё
function filter_media_release_current_term( $query_args, $sfid ) {
if($sfid==2530 || $sfid==2488)
{
$currentafter = 2025;
$startyear = '2025';
$aftermonth = '01';
$afterday = '01';
$currentbefore = '2025';
// edit later to use a full date, not just year
// if no date query set the after value
if (!isset($query_args['date_query'])) {
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'inclusive' => true,
);
} else {
// One or both dates are entered: see if they entered a 'To:' date and grab those values
if (isset($query_args['date_query']['before']) && isset($query_args['date_query']['before']['year'])) {
$currentbefore = $query_args['date_query']['before']['year'];
$beforeday = $query_args['date_query']['before']['day'];
$beforemonth = $query_args['date_query']['before']['month'];
if ($currentbefore < $startyear) {
// can't return any results prior to the start date - resets the date query to default
print_r("
Enter dates starting " . $aftermonth ."/" . $afterday . "/" . $startyear . "
");
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'inclusive' => true,
);
} else {
// Before date is valid
// Did they enter a 'From:' date?
if (isset($query_args['date_query']['after']) && isset($query_args['date_query']['after']['year'])) {
$currentafter = $query_args['date_query']['after']['year'];
// if before start date - reset it to the start date but keep the before entry
if ($currentafter < $startyear) {
print_r("
Start date out of range!
");
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'before' => array (
'day' => $beforeday,
'month' => $beforemonth,
'year' => $currentbefore,
),
'inclusive' => true,
);
} // no else here - do nothing if both dates are in the valid range
} else {
// no 'From:' date entered - use default from date and the 'To:' date they entered
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'before' => array (
'day' => $beforeday,
'month' => $beforemonth,
'year' => $currentbefore,
),
'inclusive' => true,
);
}
}
} else {
// they entered only the 'From:' value but make sure it is set to avoid errors
if (isset($query_args['date_query']['after']) && isset($query_args['date_query']['after']['year'])) {
$currentafter = $query_args['date_query']['after']['year'];
// if before start date - reset it to the start date but keep the before entry
if ($currentafter < $startyear) {
print_r("
Start date out of range!
");
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'inclusive' => true,
);
} // no else here - do nothing if the date is in the valid range
} else {
// no year set for some reason
$query_args['date_query'] =
array(
'after' => array (
'day' => $afterday,
'month' => $aftermonth,
'year' => $startyear,
),
'inclusive' => true,
);
}
}
}
}
return $query_args;
}
add_filter( 'sf_edit_query_args', 'filter_media_release_current_term', 20, 2 );
Подробнее здесь: https://stackoverflow.com/questions/797 ... rm-is-used