Skip to content

Instantly share code, notes, and snippets.

@qwersk
Created September 21, 2017 05:09
Show Gist options
  • Save qwersk/2898897fe4bc8a8399072c82c807a168 to your computer and use it in GitHub Desktop.
Save qwersk/2898897fe4bc8a8399072c82c807a168 to your computer and use it in GitHub Desktop.
Search post by title #WORDPRESS #WP
<?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