Default category on listing submit not working

I’m using this code to set placeholder and default category. the placeholder works but the default category isn’t. what I’m doing wrong?

add_filter(
	'hivepress/v1/forms/listing_submit',
	function( $form ) {
	
		if(isset($form['fields']['categories'])){
			$form['fields']['categories']['placeholder'] = 'choose category';
			$form['fields']['categories']['default'] = 116;
		}
		
		return $form;
	},
	1000
	);

Another question please.
If I want the same code to be in the listing submit and listing update page and to avoid additional lines. can I use the same code for 2 paths? like this:

add_filter(
	'hivepress/v1/forms/listing_submit', 'hivepress/v1/forms/listing_update',
	function( $form ) {
	
		if(isset($form['fields']['title'])){
			$form['fields']['title']['placeholder'] = 'choose title';
		}
		
		return $form;
	},
	1000
	);

Or any other way to use the same code for 2 pages?

  1. Please try this PHP snippet to set the default category for the new listings. Please just number 1 on the category id
add_action(
	'hivepress/v1/models/listing/create', 
	function($listing_id, $listing) {
		$listing->set_categories([1])->save_categories();
	},
	1000,
	2
);
  1. It is possible to use only hook hivepress/v1/forms/listing_update. The hivepress/v1/forms/listing_submit hook inherits changes for the hivepress/v1/forms/listing_update

I tried the PHP snippet I try to stay with “1” and also change the number to “116” which is the number of the category, but it’s not helping. still, show “select category” when creating a listing.

Please try registering a new user and adding a listing, or finish adding the current listing and add a new one. The suggested snippet sets the category ID on creation, and the one you’re adding may be an existing draft.

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