How to add 2 new fields country and states

i want to add 2 new fileds country and states.
how to do that?
i dont wana use geolocation.

help me in right direction.

Have you read the documentation ?

Hi,

You can add new fields using the Listing Attributes, please see this doc: How to add listing attributes - HivePress Help Center

​I hope this is helpful to you.

thanks for the information. it did not help. i already know that. my question is this??
how can i achieve this in listing page??

When a user selects their “Country” from the 1st drop down menu, then those “States & Provinces” automatically populate in the 2nd drop down menu below called “State/Province:”…

i dont want to use geolocation and i want it to be in our website also it should be searchable. can you point me in a right direction??

very bad support. no one willing to help

Hi,

Sorry for the inconvenience. Please note that our extension has three options to achieve what you need:

  1. Using the Geolocation extension.

  2. Add these fields using the listing attribute. However, note that you will need to add all locations manually.

  3. Add this functionality using custom code.

As the first two options do not suit you, we cannot help with the last option, as custom implementation is beyond our support. I recommend that you review the policy in more detail at this link: Support Policy | HivePress

Nevertheless, you can always consider hiring experts: Customize your website | HivePress

I believe this will be useful to you.

Hello andrii, thanks for your quick response.

i have a news i created a code thats work fine now. i want your tiny help.
here is my code: hivepress plugin >> includes >> fields >> class-country-selector.php · GitHub

it works fine. but the issue is i have put this code in the hivepress plugin.

after update it will be gone.

i tried creating a plugin then put this file in the includes >> fields folder in my plugin.
js files i put them in JS folder.

but then this new attribute never appear.

how can i put it in the new plugin. can you check and point me. thanks

Hi,

You can add custom code using this documentation, then it will not be removed: How to add custom code snippets - HivePress Help Center

Also, you can create your own extension and add the code there: https://docs.hivepress.io/developer-docs/tutorials/create-a-custom-hivepress-extension

​I hope this is helpful to you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

If one adds an attribute for country and city and provinces etc then it helps but issue is how to enter all the data for each city and state.

@madhvendras84 made a post with some code.

could you detail the steps you followed to get the solution with the exhaustive list of cities etc

@madhvendras84 Hope you see this. THanks

How can we populate many cities etc into the database.

hi @madhvendras84 Did you manage to put the 1000s of cities ? it is hard to do this manually. How did you do it ? A solution where it does not get lost on update ?

yes i custom coded and achieved it. Hivepress did not help at all

Please could you share how you achieved it. if you click my profile pic and see it shows my contact info. kindly touchbase.

MadhvendraAs84@gmail.com
WhatsApp +918299483053

Hello everyone,

I am currently working on a website and wondering about the best practices for making it accessible from several countries (internationally).

I am referring to both the technical side (hosting, performance, etc.) and the user side (language, geolocation, local legal compliance, etc.).

Do you have any advice or resources you could share on this topic?

Thank you in advance for your help!


Bonjour Ă  tous,

Je travaille actuellement sur un site Web et je m’interroge sur les meilleures pratiques pour le rendre accessible depuis plusieurs pays (à l’international).
Je fais référence à la fois au côté technique (hébergement, performance, etc.) et au côté utilisateur (langue, géolocalisation, conformité juridique locale, etc.).

Avez-vous des conseils ou des ressources que vous pourriez partager sur ce sujet ?

Merci d’avance pour votre aide !

I tried something here.
A selector plugin, that reads values ​​from a csv file, it’s for car make and model, but you can easily turn it into a country-city selector. It’s just a selector because it can’t be filtered or made searchable, only display. I’m not a programmer. However, a better js selector could be written, which would be great. For filtering I saw something like Filter Everything but it definitely finds the inserted values ​​Ajax Search Lite by Ernest Marcinko. The script is basically made from your forum posts, so use it as you wish, I’m glad if it inspires someone, as your posts inspired me and if it’s helpful to someone. … but I wonder why the make and model attributes are not filterable. What is missing? Should they be registered as filterable?

1 Like

… but I wonder why the make and model attributes are not filterable. What is missing? Should they be registered as filterable?
… my programming knowledge is limited, in the digital age of geolocation I made a kind of analog locator :slight_smile: with some snippet can be made to filter. Everything I tried is there in the link above.

fields.php

<?php

add_filter('hivepress/v1/forms/listing_submit', function ($form) {
    $data = hp_csv_get_vehicle_data();

    $makes = array_keys($data);
    $models = [];

    // Populate all possible models, as the initial options for the 'model' select field.
    // The JS will then dynamically filter these.
    foreach ($data as $make => $mods) {
        foreach ($mods as $model => $_) {
            $models[$model] = $model; // Key and value are the same for simple select options
        }
    }

    $form['fields']['make'] = [
        'type' => 'select',
        'label' => 'Make',
        'options' => array_combine($makes, $makes),
        'required' => true,
        '_order' => 2,
    ];
    $form['fields']['model'] = [
        'type' => 'select',
        'label' => 'Model',
        'options' => $models, // All models initially, JS will filter
        'required' => true,
        '_order' => 3,
    ];

    return $form;
});

// Modificare aici pentru a face atributele filtrabile/searchable în admin
add_filter(
    'hivepress/v1/models/listing/attributes',
    function ($attributes) {
        $vehicle_data = hp_csv_get_vehicle_data(); // Get all vehicle data

        // Prepare make options for backend filtering/searching
        $make_options = ['' => '']; // Add an empty option
        foreach (array_keys($vehicle_data) as $make) {
            $make_options[$make] = $make;
        }

        // Prepare model options for backend filtering/searching
        // Include all models from all makes initially for backend filtering
        $model_options = ['' => '']; // Add an empty option
        foreach ($vehicle_data as $make => $models) {
            foreach ($models as $model_name => $_) {
                $model_options[$model_name] = $model_name;
            }
        }


        $attributes['make'] = [
            'label'         => 'Make',
            'type'          => 'select', // Set type to 'select' for backend filtering
            'editable'      => true,
           // 'searchable'    => true,
           // 'filterable'    => true, 
           // 'sortable'      => true,
            'indexable'     => true,
            'display_areas' => ['view_block_secondary', 'view_page_primary'],
            'options'       => $make_options, // Provide options for backend select
			'categories'    => [],
            'edit_field'    => [
                'label'     => 'Make',
                'type'      => 'select', // Keep as 'select' here as well, HivePress handles this for the frontend
                'source'    => [],
                '_external' => true,
                '_order'    => 1,
                'options'   => $make_options, // These options will be overwritten by JS on the frontend
                'required'  => true,
            ],
        ];

        $attributes['model'] = [
            'label'         => 'Model',
            'type'          => 'select', // Set type to 'select' for backend filtering
            'editable'      => true,
           // 'searchable'    => true,
           // 'filterable'    => true, 
           // 'sortable'      => true,
            'indexable'     => true,
            'display_areas' => ['view_block_secondary', 'view_page_primary'],
            'options'       => $model_options, // Provide all possible models for backend select
			'categories'    => [],
            'edit_field'    => [
                'label'     => 'Model',
                'type'      => 'select', // Keep as 'select' here, JS handles dynamic options
                'source'    => [],
                '_external' => true,
                '_order'    => 2,
                'options'   => $model_options, // These will be overwritten by JS on frontend
                'required'  => true,
            ],
        ];
        return $attributes;
    }
);

function hp_csv_get_vehicle_data() {
    static $data = null;
    if ($data !== null) return $data;

    $csv = plugin_dir_path(__FILE__) . '/../vehicles.csv';
    $data = [];

    if (file_exists($csv) && ($handle = fopen($csv, 'r')) !== false) {
        fgetcsv($handle);
        while (($row = fgetcsv($handle)) !== false) {
            list($make, $model) = $row;
            // Trim whitespace from make and model
            $make = trim($make);
            $model = trim($model);
            if (!empty($make) && !empty($model)) {
                $data[$make][$model] = true;
            }
        }
        fclose($handle);
    }
    // Sort makes alphabetically
    ksort($data);
    // Sort models within each make alphabetically
    foreach ($data as $make => $models) {
        ksort($data[$make]);
    }
    return $data;
}