Last active
September 21, 2019 13:03
-
-
Save bulentsakarya/754e51e670b58915b2472deff373eb0c to your computer and use it in GitHub Desktop.
wp tarih ekleme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load our function when hook is set | |
add_action( 'pre_get_posts', 'rc_modify_query_get_posts_older_than_today' ); | |
function rc_modify_query_get_posts_older_than_today( $query ) { | |
// Check if on frontend and main query is modified | |
if( ! is_admin() && $query->is_main_query() ) { | |
if($query->is_search()) { | |
$timeago = $_GET['timeago'] != '' ? $_GET['timeago'] : ''; | |
if($timeago == 24) { | |
$query->set( 'date_query', [ | |
[ | |
'after' => '24 hours ago', | |
] | |
] ); | |
} | |
if($timeago == 7) { | |
$query->set( 'date_query', [ | |
[ | |
'after' => '1 week ago', | |
] | |
] ); | |
} | |
if($timeago == 30) { | |
$query->set( 'date_query', [ | |
[ | |
'after' => '1 month ago', | |
] | |
] ); | |
} | |
} | |
} | |
return $query; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_date_search() { | |
if(is_search()) { | |
$search_query = get_search_query(); | |
$months = array( 1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June", 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December" ); | |
foreach($months as $month => $month_name) { | |
if(stristr($search_query, $month_name)) { | |
$m = $month; | |
preg_match('/(19[0-9][0-9]|20[0-9][0-9])/', $search_query, $year); | |
if($year) | |
$y = $year[0]; | |
preg_match('/^[0-3]{0,1}[0-9]{1} /', $search_query, $day); | |
if($day) | |
$d = $day[0]; | |
} | |
} | |
if(isset($d) && isset($m) && isset($y)) { | |
$wd = explode($y, $search_query); | |
if($wd[1]) | |
$query_string = 's=' . trim($wd[1]) . '&year=' . $y . '&monthnum=' . $m . '&day=' . $d; | |
else | |
$query_string = 'year=' . $y . '&monthnum=' . $m . '&day=' . $d; | |
query_posts($query_string); | |
} | |
} | |
} | |
add_action('get_header', 'my_date_search'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment