Function Reference: geodir_posts_fields
Summary
Listing fields filter.
Global Values
- $wp_query
- (object) (required) WordPress Query object.
- Default: None
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
- $table
- (string) (required) Listing table name.
- Default: None
- $gd_session
- (object) (required) GeoDirectory Session object.
- Default: None
Package
GeoDirectory
Parameters
- $fields
- (string) (required) Fields query string.
- Default: None
Return Values
- (string)
- Modified fields query string.
Change Log
Since: 1.0.0
Source File
geodir_posts_fields() is located in geodirectory-functions/listing_filters.php [Line: 232]
Source Code
function geodir_posts_fields($fields) { global $wp_query, $wpdb, $geodir_post_type, $table, $plugin_prefix, $dist, $mylat, $mylon, $snear, $gd_session; // Filter-Location-Manager to add location table. $fields .= ", " . $table . ".* "; if ($snear != '' || $gd_session->get('all_near_me')) { $DistanceRadius = geodir_getDistanceRadius(get_option('geodir_search_dist_1')); if ($gd_session->get('all_near_me')) { $mylat = $gd_session->get('user_lat'); $mylon = $gd_session->get('user_lon'); } $fields .= " , (" . $DistanceRadius . " * 2 * ASIN(SQRT( POWER(SIN((ABS($mylat) - ABS(" . $table . ".post_latitude)) * pi()/180 / 2), 2) +COS(ABS($mylat) * pi()/180) * COS( ABS(" . $table . ".post_latitude) * pi()/180) *POWER(SIN(($mylon - " . $table . ".post_longitude) * pi()/180 / 2), 2) )))as distance "; } global $s; if (is_search() && isset($_REQUEST['geodir_search']) && $s && trim($s) != '') { $keywords = explode(" ", $s); if(is_array($keywords) && $klimit = get_option('geodir_search_word_limit')){ foreach($keywords as $kkey=>$kword){ if(geodir_utf8_strlen($kword)<=$klimit){ unset($keywords[$kkey]); } } } if (count($keywords) > 1) { $parts = array( 'AND' => 'gd_alltitlematch_part', 'OR' => 'gd_titlematch_part' ); $gd_titlematch_part = ""; foreach ($parts as $key => $part) { $gd_titlematch_part .= " CASE WHEN "; $count = 0; foreach ($keywords as $keyword) { $keyword = trim($keyword); $keyword = wp_specialchars_decode($keyword ,ENT_QUOTES); $count++; if ($count < count($keywords)) { // $gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' " . $key . " "; $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) " . $key . " "; } else { //$gd_titlematch_part .= $wpdb->posts . ".post_title LIKE '%%" . $keyword . "%%' "; $gd_titlematch_part .= "( " . $wpdb->posts . ".post_title LIKE '" . $keyword . "' OR " . $wpdb->posts . ".post_title LIKE '" . $keyword . "%%' OR " . $wpdb->posts . ".post_title LIKE '%% " . $keyword . "%%' ) "; } } $gd_titlematch_part .= "THEN 1 ELSE 0 END AS " . $part . ","; } } else { $gd_titlematch_part = ""; } $s = stripslashes_deep( $s ); $s = wp_specialchars_decode($s,ENT_QUOTES); $fields .= $wpdb->prepare(", CASE WHEN " . $table . ".is_featured='1' THEN 1 ELSE 0 END AS gd_featured, CASE WHEN " . $wpdb->posts . ".post_title LIKE %s THEN 1 ELSE 0 END AS gd_exacttitle," . $gd_titlematch_part . " CASE WHEN ( " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s OR " . $wpdb->posts . ".post_title LIKE %s ) THEN 1 ELSE 0 END AS gd_titlematch, CASE WHEN ( " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s OR " . $wpdb->posts . ".post_content LIKE %s ) THEN 1 ELSE 0 END AS gd_content", array($s, $s, $s . '%', '% ' . $s . '%', $s, $s . ' %', '% ' . $s . ' %', '% ' . $s)); } return $fields; }