Fill Vendor Attribute Select Field with PHP

Hi, I’m using this code to modify an existing Vendor Attribute called “My Artists”, that allows artists to link other artist’s profile. It shows up correctly in the vendor update form and even get a ‘success’ message when submitting the form but, when I refresh the page, the data disappears.
I feel like no data is being saved at all when submitting the form.
Is there a way to correct that ?
Would also be great if you could add this as a feature in the future, to allow us to dynamically set select options.

add_filter(
	'hivepress/v1/models/vendor/attributes',
	function( $attributes ) {
		$attributes[ 'my_artists' ]['edit_field']['options'] = 'users';
		$attributes[ 'my_artists' ]['edit_field']['option_args'] = [ 
			'status' 	=> 'publish',
			'role'   	=> 'contributor',
			'orderby'	=> 'id',
			'order'	 	=> 'DESC',
		];  
		
		echo json_encode($attributes);
		return $attributes;
	},
	1000
);

add_filter( 
	'hivepress/v1/models/vendor', 
	function($model){
		$attributes = hivepress()->attribute->get_attributes( 'vendor' );
		if ( isset( $attributes[ 'my_artists' ] ) ) {
			$model['fields'][ 'my_artists' ] = $attributes[ 'my_artists' ]['edit_field'];
			$model['fields'][ 'my_artists' ]['_external'] = true;
			echo json_encode($model['fields'][ 'my_artists' ]);
		}
		return $model;
	},
	1000
);

Nevermind, Actually every user setting doesn’t update anymore. I tried deactivating every plugin but nothing does it. Any I can try to update any info on the user setting page and as soon as I reload the page the changes are gone. Is there something I can do to correct this ?

Please try this PHP snippet

add_filter(
	'hivepress/v1/models/vendor/attributes',
	function( $attributes ) {
		if(isset($attributes['my_artists'])){
			$attributes[ 'my_artists' ]['edit_field'] = array_merge(
				$attributes[ 'my_artists' ]['edit_field'],
				[
					'options' => 'users',
					'option_args' => [
						'role'   	=> 'contributor',
						'orderby'	=> 'id',
						'order'	 	=> 'DESC',
					],
					'_external' => true,
				]
			);
		}
		
		return $attributes;
	},
	1000
);

Thank you for the snippet but, as stated in my second message, none of the user settings save anymore. Is there something I can do to correct this ? I already tried deactivating all plugins but it didn’t change anything.
Each time I reload the page on the user settings, the changes disappear, they’re not saved in the database even tho I receive a success message.

Attributes don’t save

I also tried deactivating my custom theme and using default taskhive one but it still didn’t make it work

Please make sure that there’s a single vendor linked to your user account in WordPress/Vendors. I’ve tested this snippet locally and it works fine, but issues occur if there are 2+ vendor profiles linked to the same user, because settings are saved for only one of them then and not the one used to populate the form values.

Thank you but I mean that absolutely none of the other attributes work either. I have lots of other attributes and they don’t work because when I update them from the user settings page at “/account/settings/” , changes are not saved. Not for any of my custom attributes. I have tried resetting tons of files already but it still doesn’t work, how can I make the settings work again ?
Thank you.

Please send temporary WP access via email to support@hivepress.io with a link to this topic and any extra details that may help detect this issue, and we’ll check it. You can send a temporary admin access link using this plugin Temporary Login Without Password – WordPress plugin | WordPress.org

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