Dear users,
Today we’ll guide you how to add additional custom fields for the “Edit a place” form.
Simply follow three below steps to get the work done:
- Add input field so that the users can add field’s value.
- Save the field to database.
- Show the field.
For example, we will try to add a new field “panopress” in the “Edit a place” form. This field will be displayed in the header tab, once you’ve complete all the change:
For your further information, PanoPress is a WordPress plugin for displaying 360 degree panoramas on your site. You can check out this following link for more detailed information about this plugin: http://www.panopress.org/
Please don’t forget to integrate PanoPress plugin first before adding the new field. Once the field is successfully implemented, users can insert a PanoPress link in the field and it will display a panoramic image on the header of the place’s single page.
Let’s take a look at the guide:
- The meta name will be panopress.
- Firstly, you can modify the file “template-js/modal-edit-place.php” to add an input field. The field name & id should be panopress.
<div class="form-field edit-cover-image"> <label><?php _e("PANOPRESS", ET_DOMAIN) ?></label> <input type="text" class="" name="panopress" id="panopress" placeholder="e.g. [pano file='http://asturias360.com/panara/']"/> </div> <div class="form-field edit-cover-image"> <label><?php _e("VIDEO", ET_DOMAIN) ?></label> <input type="text" class="" name="et_video" id="et_video" placeholder="e.g. https://www.youtube.com/watch?v=d7MY1l3kcvo"/> </div>
- Secondly, to update the field to database, you can use the hook “ae_update_place”. It’ll help to save the place details after users submit the form.
// update panopress shortcode to datatabse add_action('ae_update_place', 'update_panopress'); function update_panopress($result){ // check the request if( isset($_REQUEST['panopress']) ) { update_post_meta($result, 'panopress', $_REQUEST['panopress']); } }
- Use filter “ae_convert_place” to add the field’ details to the place’s data.
add_filter('ae_convert_place', 'add_panopress'); function add_panopress($result){ // add panopress to convert data $result->panopress = get_post_meta($result->ID, 'panopress', true); return $result; }
- Finally, to show the field in single-place header, you should edit the file “single-place.php” as following.
if(isset($place->panopress) && $place->panopress) { ?>cover_image ) { $cover = $place->cover_image; $cover_image_url = wp_get_attachment_image_src( $cover, 'full' ); ?>
Note:
You can add the field details to place info by editing template/single-place-details.php
If you want to add Input field to “Submit place” form, you can edit the file “template/post-place-step3.php” and use hook ae_insert_place
add_action(‘ae_insert_place’, ‘update_panopress’);
You can also use hook “the_content” to show field’s info below the “ Place’s description”.
add_filter('the_content', 'show_field_below_description'); function show_field_below_description($content){ global $post; $panopress = get_post_meta($post->ID, 'panopress', true); return $content.''; }
That’s all!