There is a way to enable your directorist listings to edit the expiration date and assign ‘Never Expire’ in bulk. Please follow the instructions given below to achieve this feature on your website.
Please add the following code at the end of the “functions.php” file of the currently activated theme or child theme folder. It is always better to use a child theme for implementing custom codes. If you do not want to use theme files, you can use any “Code Snippet” plugin to implement the code.
add_filter('bulk_edit_custom_box', 'directorist_custom_box_never_expire', 10, 2);
add_filter('quick_edit_custom_box', 'directorist_custom_box_never_expire', 10, 2);
function directorist_custom_box_never_expire($column_name, $post_type)
{
if (('atbdp_date' === $column_name) && (ATBDP_POST_TYPE == $post_type)) {
?>
<fieldset class="inline-edit-col-right" style="margin-top: 0;">
<div class="misc-pub-section misc-pub-atbdp-never-expires">
<label>
<input type="checkbox" name="never_expire" value="1" />
<strong>Never Expires</strong>
</label>
<div class="atbdp_expiry_date">
<label><strong>Expiry Date</strong></label>
<input type="datetime-local" name="expiry_date" />
</div>
</div>
</fieldset>
<?php
};
}
add_action('save_post', 'directorist_custom_box_never_expire_save');
function directorist_custom_box_never_expire_save($post_id)
{
if (!is_admin()) {
return;
}
if (get_post_type($post_id) !== ATBDP_POST_TYPE) {
return;
}
// if our current user can't edit this post, bail
if (!current_user_can('edit_posts')) {
return;
}
// Make sure that it is set.
if (isset($_REQUEST['never_expire']) && !empty($_REQUEST['never_expire'])) {
update_post_meta($post_id, '_never_expire', sanitize_text_field($_REQUEST['never_expire']));
}
if (isset($_REQUEST['expiry_date']) && !empty($_REQUEST['expiry_date'])) {
update_post_meta($post_id, '_expiry_date', sanitize_text_field($_REQUEST['expiry_date']));
update_post_meta($post_id, '_never_expire', 0);
}
}
add_action('admin_footer', function(){
?>
<script>
jQuery(document).ready(function($){
$('.misc-pub-atbdp-never-expires input[name="never_expire"]').change(function(){
if( $(this).is(":checked") ){
$('.misc-pub-atbdp-never-expires .atbdp_expiry_date').hide();
$('.misc-pub-atbdp-never-expires input[name="expiry_date"]').val('');
}else{
$('.misc-pub-atbdp-never-expires .atbdp_expiry_date').show();
}
});
});
</script>
<?php
});
After implementing the code successfully, when you try to bulk edit the listings from the admin panel you will find two new options to set the expiration date and never expire.
![](https://directorist.com/knowledge-base/wp-content/uploads/sites/7/2023/08/image-1024x463.png)
Here’s a method to perform a bulk update of the expiration date. We believe this article will assist you in tailoring your website and enhancing its user-friendliness.