Data wont save when pulling values for select from API

Is there official documentation on this - attributes not an option in the filter

add_filter(
	'hivepress/v1/models/listing/attributes', function( $attributes ) {
	$attributes['towns'] = [
            'editable'   => true, 

full current code is add_filter(
	'hivepress/v1/models/listing/attributes', function( $attributes ) {
	$attributes['towns'] = [
            'editable'   => true,
            'searchable' => true, // Make the attribute searchable
            //'filterable'  => true,
            'sortable'  => true,
            'indexable'  => true,
            'display_areas' => ['view_block_secondary','view_page_primary','view_page_secondary'],

            'edit_field' => [
                'label'     => 'Town',
                'type'      => 'select',
                'source'    => hivepress()->router->get_url('http://api.geonames.org/searchJSON?country=IE&featureClass=P&maxRows=1000&username=swdadmin'),
                '_external' => true,
                '_order'    => 103,
                'options'   => fetch_irish_towns_from_geonames(),
                'required'  => false,
                'attributes'  => _location,
                'data-options' => wp_json_encode(
                [
                'disable-search' => false
                ]),

                
            ],

But it throws errors: Warning : Undefined variable $attributes in /home/customer/www/storycinn.com/public_html/wp-content/themes/listinghive/functions.php on line 76

Fatal error : Uncaught Error: Undefined constant “_location” in /home/customer/www/storycinn.com/public_html/wp-content/themes/listinghive/functions.php:28 Stack trace: #0 /home/customer/www/storycinn.com/public_html/wp-includes/class-wp-hook.php(324): {closure}(Array) #1 /home/customer/www/storycinn.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #2 /home/customer/www/storycinn.com/public_html/wp-content/plugins/hivepress/includes/components/class-attribute.php(590): apply_filters(‘hivepress/v1/mo…’, Array) #3 /home/customer/www/storycinn.com/public_html/wp-includes/class-wp-hook.php(324): HivePress\Components\Attribute->register_attributes(‘’) #4 /home/customer/www/storycinn.com/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #5 /home/customer/www/storycinn.com/public_html/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #6 /home/customer/www/storycinn.com/public_html/wp-settings.php(700): do_action(‘init’) #7 /home/customer/www/storycinn.com/public_html/wp-config.php(103): require_once(‘/home/customer/…’) #8 /home/customer/www/storycinn.com/public_html/wp-load.php(50): require_once(‘/home/customer/…’) #9 /home/customer/www/storycinn.com/public_html/wp-blog-header.php(13): require_once(‘/home/customer/…’) #10 /home/customer/www/storycinn.com/public_html/index.php(17): require(‘/home/customer/…’) #11 {main} thrown in /home/customer/www/storycinn.com/public_html/wp-content/themes/listinghive/functions.php on line 28

There has been a critical error on this website.

THe values are to be dynamic if I send the current request its not pulling the dynamic value change. So it works for the initial set value but not on values that are outside the intial value

Sorry, while I can provide general guidance I can’t debug custom code or suggest detailed changes, this is beyond the support scope. Please check the hook reference and the code reference in the Developers menu https://hivepress.io/ This way you can always check which parameters are passed to hooks, which functions are called etc.

If the purpose of the customization is adding the location selection and search I highly recommend considering the Geolocation extension with modifications instead.

I know I am tempted to test the geolocation but I litterly have the content working - all I need to to is allow the values. Is it possible to turn off the validation function for the given field. I have the fields populating as required but the validation is what is preventing full function.

Unfortunately there’s no easy way to turn it off, but if the back-end validation fails this means that the options are populated on the front-end only, Please make sure that they are populating everywhere, and if instead of the hivepress/v1/models/listing/attributes hooks there’s another one (e.g. the form hook) then the field should be added also to the listing model itself via hivepress/v1/models/listing, otherwise it will be displayed ok in the form, but tha validation will fail when saving the listing.

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