Function Reference: geodir_post_custom_fields

Summary

Returns custom fields based on page type. (detail page, listing page).

Global Values

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

Default: None

Package

GeoDirectory

Parameters

$package_id
(int|string) (required) The package ID.

Default: None
$default
(string) (optional) When set to “default” it will display only default fields.

Default: None
$post_type
(string) (optional) The wordpress post type.

Default: None
$fields_location
(string) (optional) Where exactly are you going to place this custom fields?.

Default: None

Return Values

(array|mixed|void)
  • Returns custom fields.

Change Log

Since: 1.0.0

Filters

‘geodir_filter_geodir_post_custom_fields’ [Line: 148]

Source File

geodir_post_custom_fields() is located in geodirectory-functions/custom_fields_functions.php [Line: 73]

Source Code

function geodir_post_custom_fields($package_id = '', $default = 'all', $post_type = 'gd_place', $fields_location = 'none')
{
    global $wpdb, $geodir_post_custom_fields_cache;

    $cache_stored = $post_type . '_' . $package_id . '_' . $default . '_' . $fields_location;

    if (array_key_exists($cache_stored, $geodir_post_custom_fields_cache)) {
        return $geodir_post_custom_fields_cache[$cache_stored];
    }

    $default_query = '';

    if ($default == 'default')
        $default_query .= " and is_admin IN ('1') ";
    elseif ($default == 'custom')
        $default_query .= " and is_admin = '0' ";

    if ($fields_location == 'none') {
    } else{
        $fields_location = esc_sql( $fields_location );
        $default_query .= " and show_in LIKE '%%[$fields_location]%%' ";
    }

    $post_meta_info = $wpdb->get_results(
        $wpdb->prepare(
            "select * from " . GEODIR_CUSTOM_FIELDS_TABLE . " where is_active = '1' and post_type = %s {$default_query} order by sort_order asc,admin_title asc",
            array($post_type)
        )
    );


    $return_arr = array();
    if ($post_meta_info) {

        foreach ($post_meta_info as $post_meta_info_obj) {

            $custom_fields = array(
                "name" => $post_meta_info_obj->htmlvar_name,
                "label" => $post_meta_info_obj->clabels,
                "default" => $post_meta_info_obj->default_value,
                "type" => $post_meta_info_obj->field_type,
                "desc" => $post_meta_info_obj->admin_desc);

            if ($post_meta_info_obj->field_type) {
                $options = explode(',', $post_meta_info_obj->option_values);
                $custom_fields["options"] = $options;
            }

            foreach ($post_meta_info_obj as $key => $val) {
                $custom_fields[$key] = $val;
            }

            $pricearr = array();
            $pricearr = explode(',', $post_meta_info_obj->packages);

            if ($package_id != '' && in_array($package_id, $pricearr)) {
                $return_arr[$post_meta_info_obj->sort_order] = $custom_fields;
            } elseif ($package_id == '') {
                $return_arr[$post_meta_info_obj->sort_order] = $custom_fields;
            }
        }
    }
    $geodir_post_custom_fields_cache[$cache_stored] = $return_arr;

    if (has_filter('geodir_filter_geodir_post_custom_fields')) {
        /**
         * Filter the post custom fields array.
         *
         * @since 1.0.0
         *
         * @param array $return_arr Post custom fields array.
         * @param int|string $package_id The package ID.
         * @param string $post_type Optional. The wordpress post type.
         * @param string $fields_location Optional. Where exactly are you going to place this custom fields?.
         */
        $return_arr = apply_filters('geodir_filter_geodir_post_custom_fields', $return_arr, $package_id, $post_type, $fields_location);
    }

    return $return_arr;
}