Join our new community forum for support & discussion

Join Now

Home Support Themes TaskHive In add listing how to change the field “image” to not optional

In add listing how to change the field “image” to not optional

  • Author
    Posts
  • sergiop63

    Hi! I just want to know In add listing how to change the field “image” to not optional

    yevhen developer

    Please try this PHP snippet

    add_filter(
    	'hivepress/v1/models/listing',
    	function( $model ) {
    		$model['fields']['images']['required']  = true;
    
    		return $model;
    	},
    	1000
    );
    sergiop63

    Hey! that works for the image as requiered thank you! but…. now there is a new field called “location” in the listing form and also in the search bar, how can I delete it?

    yevhen developer

    There are two ways to remove location field from search and listing forms:
    – Disable HivePress Geolocation extension.
    – If HivePress Geolocation extension is needed then you can just hide this field with this PHP snippet

    // Delete field from search bar.
    add_filter(
    	'hivepress/v1/forms/listing_search',
    	function( $form ) {
    		if ( isset( $form['fields']['location'] ) ) {
    			unset($form['fields']['location']);
    		}
    
    		return $form;
    	},
    	1000
    );
    
    // Delete field from listing form.
    add_filter(
    	'hivepress/v1/forms/listing_update',
    	function( $form ) {
    		if ( isset( $form['fields']['location'] ) ) {
    			unset($form['fields']['location']);
    		}
    
    		return $form;
    	},
    	1000
    );
    fixpaana

    Hi yevhen. I was facing a similar problem on my website where I wanted to make the Images field required and not keep it optional. I followed your advice and used the “Insert PHP Code Snippet” plugin to do the job. I copy pasted the snippet in the plugin and activated it.

    This unfortunately didn’t cause any change in the result. It still says “Optional” next to the images field in the Add Details page. Would appreciate any help or tips that you may have to offer

    yevhen developer

    We test it locally and it seems to be ok. Please make sure that you added the code snippet correctly. Also, you can try Code Snippets plugin to put snippets on your website https://wordpress.org/plugins/code-snippets/

Viewing 6 posts - 1 through 6 (of 6 total)

New Reply

This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.