How set default value for categories

I want to set a default value for the categories on submit listing for the taskhive theme. Don’t know if there is a configuration option, but I have tried adding a function to the functions.php.
I saw this example

<?php
add_filter(
	'hivepress/v1/forms/listing_update',
	function( $form ) {
		if ( isset( $form['fields']['booking_slot_duration'] ) ) {
			$form['fields']['booking_slot_duration']['default'] = 123;
		}

		return $form;
	},
	1000
);

but doesn’t seem to work, I think the field here is a textbox.

Anybody knows set the default value for a dropdown?

Hi,

Please use these samples: Disable listing category from Add Listing page. Please note that you need to add your custom code exclusively using this doc: How to add custom code snippets - HivePress Help Center, if you edit our product files directly, they will be automatically deleted after our update.

Please note that it can require further customization.

​I hope this is helpful to you.

Hi @andrii

This didn’t seem to work, I used this script only

add_action(
	'hivepress/v1/models/listing/create', 
	function($listing_id, $listing) {
		$listing->set_categories(category_id_here)->save_categories();
	}, 
	1000, 
	2
);

But the page gives an error after saving. Yes, I changed the category id.
This script applies when saving the listing?

My scenario is this:

  • The user creates a listing with category “A”. Successfully.
  • Comes back to create another listing.
  • At this point the select control has category “A” preselected, so if the user does not changes it the price fields and other won’t appear.

I need a way to have the categories control to have a default value to “-” or whatever the non-selected category be

Hi,

I see. Unfortunately, there is no such function, it will require a detailed check and custom implementation.

That seems like a bug! This is not crazy request! The form hides price, tiers and other important features if a category is not changed.

Hi,

As I clarified in my last post, unfortunately, there is no simple solution here, it will require a custom implementation. Please note that we only provide general recommendations and support for existing features, and customization is not within the scope of our support: Support Policy | HivePress.

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