Function Reference: author_filter_where

Summary

Where filter for author listing.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$table
(string) (required) Listing table name.

Default: None

Package

GeoDirectory

Parameters

$where
(string) (required) The where query string.

Default: None

Return Values

(string)
  • Modified where query string.

Change Log

Since: 1.0.0

Source File

author_filter_where() is located in geodirectory-functions/listing_filters.php [Line: 926]

Source Code

function author_filter_where($where) {
    global $wpdb, $geodir_post_type, $table, $curr;

    $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author'));
    $user_id = !empty($curauth->ID) ? (int)$curauth->ID : 0;

    if (isset($_REQUEST['stype'])) {
        $where = $wpdb->prepare(" AND $wpdb->posts.post_type IN (%s) ",$_REQUEST['stype']);
    } else {
        $where = " AND $wpdb->posts.post_type IN ('gd_place') ";
    }

    if ($user_id > 0) {
        if (isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite') {
            $user_fav_posts = geodir_get_user_favourites($user_id);
            $user_fav_posts = !empty($user_fav_posts) && is_array($user_fav_posts) ? implode("','", $user_fav_posts) : '-1';
            $where .= " AND $wpdb->posts.ID IN ('$user_fav_posts')";
        } else
            $where .= " AND $wpdb->posts.post_author = $user_id";

        if ($user_id == (int)get_current_user_id()) {
            $where .= " AND $wpdb->posts.post_status IN ('publish','draft','pending') ";
        } else {
            $where .= " AND $wpdb->posts.post_status = 'publish' ";
        }
    } else {
        $where .= " AND $wpdb->posts.post_author = '-1' AND $wpdb->posts.post_status = 'publish' ";
    }

    ########### WPML ###########
    if (geodir_wpml_is_post_type_translated(sanitize_text_field($_REQUEST['stype']))) {
        $lang_code = ICL_LANGUAGE_CODE;
        if ($lang_code) {
            $where .= " AND icl_t.language_code='" . $lang_code . "' ";
        }

    }
    ########### WPML ###########

    return $where;
}