Make taxonomy mandatory field

I have created a custom taxonomy in CustomPress and want to make it mandatory when user is creating or editing a listing.

Here is the code that controls the Taxonomies for my edit listing page / page-update-listing.php
If you would like me to upload the full page code please just let me know.

<!-- Start Taxonimy, Category and custom All Services-->
		<?php
		//get related hierarchical taxonomies
		$taxonomies = get_object_taxonomies('directory_listing', 'objects');
		$taxonomies = empty($taxonomies) ? array() : $taxonomies;

		//Loop through the taxonomies that apply
		foreach($taxonomies as $taxonomy):
		if( ! $taxonomy->hierarchical) continue;
		$tax_name = $taxonomy->name;
		$labels = $taxonomy->labels;
		//Get this Taxonomies terms
		$selected_cats = array_values( wp_get_post_terms($listing_data['ID'], $tax_name, array('fields' => 'ids') ) );

		?>

		<div id="taxonomy-<?php echo $tax_name; ?>" class="dr_taxonomydiv">
			<label><?php echo $labels->all_items; ?></label>

			<div id="<?php echo $tax_name; ?>_all" class="dr_tax_panel">
				<?php
				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
				echo "<input type='hidden' name='{$name}[]' value='0' />"; 		// Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
				?>
				<ul id="<?php echo $tax_name; ?>_checklist" class="list:<?php echo $labels->name; ?> categorychecklist form-no-clear">
					<?php wp_terms_checklist( 0, array( 'taxonomy' => $tax_name, 'selected_cats' => $selected_cats, 'checked_ontop' => false ) ) ?>
				</ul>
			</div>
		</div>
		<?php endforeach; ?>
<!-- End Taxonimy, Category and custom All Services-->

This is a multi-site and I was unable to find where to activate support access. If you need me to send login creds let me know.

Thanks,
William

  • James Morris
    • WordPress Enthusiast

    Hello William,

    I hope you are well today.

    Since we're dealing with a custom template, the safer bet would be to access your site directly rather than Support Staff Login. That way if there is a minor syntax error it can be fixed without bringing your site down.

    Would you please grant me access to your site and server?

    Please visit the Contact page and complete the form with the following information:

    Select "I have a different question" from the drop-down box.

    Subject: "Attn: James Morris"

    In the Message box, please provide the following:

    - link back to this thread for reference
    - any other relevant urls

    - Admin login:
    Admin username
    Admin password
    Login url

    - Hosting Control Panel Login
    Admin username
    Admin password
    Login url

    - FTP credentials
    host
    username
    password
    (and port if required)

    Best regards,

    James Morris

  • James Morris
    • WordPress Enthusiast

    Hello William,

    I hope you are well today.

    I've been doing some digging around and, unfortunately, CustomPress does not have the ability to make taxonomies required out of the box. This would be in the realm of custom coding to have that level of functionality.

    I was able to see and edit listings from the Dashboard of your site, but I could not find where you are allowing Agents to edit from the frontend. If you were using shortcodes to display your fields, then you may be able to use some jQuery to do some basic validation. But other than that, I'm afraid this is something that's not possible with CustomPress at this point in time.

    The following thread covers some jQuery examples with CustomPress: https://premium.wpmudev.org/forums/topic/custompress-when-using-the-ct_in-shortcode-can-a-field-be-not-required

    If you would like, I could add this to the Features & Feedback forum to let the developers know this is a desired feature.

    Best regards,

    James Morris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.