Function Reference: geodir_get_custom_sort_options

Summary

Get sort options based on post type.

Global Values

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

Default: None

Package

GeoDirectory

Parameters

$post_type
(string) (required) The post type.

Default: None

Return Values

(bool|mixed|void)
  • Returns sort options when post type available.
  • Otherwise returns false.

Change Log

Since: 1.0.0

Source File

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

Source Code

function geodir_get_custom_sort_options($post_type = '')
{

    global $wpdb;

    if ($post_type != '') {

        $all_postypes = geodir_get_posttypes();

        if (!in_array($post_type, $all_postypes))
            return false;

        $fields = array();

        $fields[] = array(
            'post_type' => $post_type,
            'data_type' => '',
            'field_type' => 'random',
            'site_title' => 'Random',
            'htmlvar_name' => 'post_title',
            'field_icon' =>  'fa fa-random',
            'description' =>  __('Random sort (not recommended for large sites)', 'geodirectory')
        );

        $fields[] = array(
            'post_type' => $post_type,
            'data_type' => '',
            'field_type' => 'datetime',
            'site_title' => __('Add date', 'geodirectory'),
            'htmlvar_name' => 'post_date',
            'field_icon' =>  'fa fa-calendar',
            'description' =>  __('Sort by date added', 'geodirectory')
        );
        $fields[] = array(
            'post_type' => $post_type,
            'data_type' => '',
            'field_type' => 'bigint',
            'site_title' => __('Review', 'geodirectory'),
            'htmlvar_name' => 'comment_count',
            'field_icon' =>  'fa fa-commenting-o',
            'description' =>  __('Sort by the number of reviews', 'geodirectory')
        );
        $fields[] = array(
            'post_type' => $post_type,
            'data_type' => '',
            'field_type' => 'float',
            'site_title' => __('Rating', 'geodirectory'),
            'htmlvar_name' => 'overall_rating',
            'field_icon' =>  'fa fa-star-o',
            'description' =>  __('Sort by the overall rating value', 'geodirectory')
        );
        $fields[] = array(
            'post_type' => $post_type,
            'data_type' => '',
            'field_type' => 'text',
            'site_title' => __('Title', 'geodirectory'),
            'htmlvar_name' => 'post_title',
            'field_icon' =>  'fa fa-sort-alpha-desc',
            'description' =>  __('Sort alphabetically by title', 'geodirectory')
        );

        /**
         * Hook to add custom sort options.
         *
         * @since 1.0.0
         * @param array $fields Unmodified sort options array.
         * @param string $post_type Post type.
         */
        return $fields = apply_filters('geodir_add_custom_sort_options', $fields, $post_type);

    }

    return false;
}