Created
September 21, 2017 05:09
-
-
Save qwersk/2898897fe4bc8a8399072c82c807a168 to your computer and use it in GitHub Desktop.
Search post by title #WORDPRESS #WP
This file contains 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
<?php | |
add_filter( 'posts_search', '__search_by_title_only', 500, 2 ); | |
function get_city_data($city = ""){ | |
if(empty($city)){ | |
if(isset($_COOKIE["city"])){ | |
$result = array(); | |
$city = urldecode($_COOKIE["city"]); | |
if($city != "Красноярск"){ | |
$city = "Иркутск"; | |
} | |
$query = new WP_Query( | |
array( | |
's' => $city, | |
'post_type' => 'cities', | |
'posts_per_page' => -1 | |
) | |
); | |
if ( $query->have_posts() ) : | |
//$count = 0; | |
while ( $query->have_posts() ) : | |
$query->the_post(); | |
$phones = get_field("phones"); | |
$addresses = get_field("addresses"); | |
$emails = get_field("emails"); | |
$result["title"] = get_the_title(); | |
$result["phones"] = $phones; | |
$result["addresses"] = $addresses; | |
$result["emails"] = $emails; | |
//$count++; | |
endwhile; | |
wp_reset_postdata(); | |
endif; | |
return $result; | |
} | |
} | |
return false; | |
} | |
remove_filter( 'posts_search', '__search_by_title_only', 500 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment