# How set default value for categories

**URL:** <https://community.hivepress.io/t/how-set-default-value-for-categories/9501>\
**Category:** HivePress\
**Created:** [February 1, 2024, 1:49am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501 "2024-02-01T01:49:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tochecr](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/6bbea6/32.png) [@tochecr](https://community.hivepress.io/u/tochecr)\
**Post date:** [February 1, 2024, 1:49am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/1 "2024-02-01T01:49:23Z")

</div>

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

```auto
<?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?

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [February 1, 2024, 10:08am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/3 "2024-02-01T10:08:03Z")

</div>

Hi,

Please use these samples: [Disable listing category from Add Listing page](https://community.hivepress.io/t/disable-listing-category-from-add-listing-page/4820). Please note that you need to add your custom code exclusively using this doc: [How to add custom code snippets - HivePress Help Center](https://help.hivepress.io/article/23-how-to-add-custom-code-snippets), 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.

---

<div class="post-metadata">

**Author:** ![tochecr](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/6bbea6/32.png) [@tochecr](https://community.hivepress.io/u/tochecr)\
**Post date:** [February 2, 2024, 3:08am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/4 "2024-02-02T03:08:09Z")

</div>

Hi @andrii

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

```auto
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

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [February 2, 2024, 9:01am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/6 "2024-02-02T09:01:56Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![tochecr](https://community.hivepress.io/letter_avatar_proxy/v4/letter/t/6bbea6/32.png) [@tochecr](https://community.hivepress.io/u/tochecr)\
**Post date:** [February 3, 2024, 12:23am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/7 "2024-02-03T00:23:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andrii](https://community.hivepress.io/user_avatar/community.hivepress.io/andrii/32/2951_2.png) [@andrii](https://community.hivepress.io/u/andrii)\
**Post date:** [February 5, 2024, 9:24am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/9 "2024-02-05T09:24:52Z")

</div>

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](https://hivepress.io/support-policy/).

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [March 6, 2024, 9:25am UTC](https://community.hivepress.io/t/how-set-default-value-for-categories/9501/10 "2024-03-06T09:25:09Z")

</div>

Closed on March 6, 2024, 9:25am UTC

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