How to Add Custom Taxonomies to Create/Edit Listing Form (form-listing.php)?
I have searched the forums and docs for this subject but cannot find any solutions. I want to add a few custom taxonomies to the "Create Listing" form for frontend users to input while creating a new listing. I can display the custom taxonomies just fine by adding the proper code to the form-listing.php file, but the custom taxonomies are not saved to the listing when the user submits the listing. For example, I have registered the custom taxonomy "Business Hours" for the custom post type 'listings' via the functions.php file and I can display this taxonomy as a dropdown within the create listing form using the function
Code:
wp_dropdown_categories
but when the user submits the form the "Business Hours" field in the single listing page is empty.
Here is the full dropdown function:
Code:
<div class="form-field">
<?php wp_dropdown_categories( array(
'taxonomy' => 'bhours',
'hide_empty' => false,
'hierarchical' => true,
'name' => 'bhours',
'id' => 'bhours',
'selected' => $listing-> bhours,
'show_option_none' => __( 'Business Hours:', APP_TD ),
'class' => 'required',
'orderby' => 'name',
'include' => $listing_cat,
'hide_if_empty' => false,
) ); ?>
</div>
The same thing happens when I display the custom taxonomy as a text field using the following function:
Code:
<label>
<?php _e( 'Business Hours', APP_TD ); ?>
<input id="listing-bhours" name="bhours" type="text" value="<?php echo esc_attr( $listing->bhours ); ?>" class="required" />
</label>
The only way I have been able to get the custom taxonomy entered in the create listing form to actually populate the correct field within the single listing page is by making a Walker checkbox as follows:
Code:
<?php
$args = array(
'taxonomy' => 'bhours',
'title_li' => '',
'walker' => New Walker_Category_Checklist,
'hide_empty' => false,
'checked_ontop' => false,
);
?>
<ul class="categorieschecklist">
<?php wp_list_categories( $args ); ?>
</ul>
But I don't want to have to use a checkbox for all of my custom taxonomies which I want to include in the create listing form. So why does the data correctly save and display when I use the Walker function, but the same data will not save and display if I use any other function such as
Code:
wp_dropdown_categories
or a radio or text field?
Last edited by sjs719; June 17th, 2015 at 06:51 PM.
Reason: typo