Getting a Fatal Error using wp_terms_checklist() in one of my advanced search form in Front End.

Fatal error: Call to undefined function wp_terms_checklist()

With search I got that it’s creating problem because the function is for admin panel use only, BTW not deprecated.

<?php
$args = array(
    'descendants_and_self'  => 0,
    'selected_cats'         => false,
    'popular_cats'          => false,
    'walker'                => null,
    'taxonomy'              => 'mytaxonomy',
    'checked_ontop'         => true
);
wp_terms_checklist( 0, $args );
?>

But if I need a similar thing in my front end. How can I achieve that? Is that possible in current flow?

1 Answer
1

You could just include it in your functions.php:

if ( ! is_admin() ) {
    include ABSPATH . 'wp-admin/includes/template.php';
}

Or better (as suggested by @Lance Cleveland in the comments):

if ( ! function_exists( 'wp_terms_checklist' ) ) {
    include ABSPATH . 'wp-admin/includes/template.php';
}

Leave a Reply

Your email address will not be published. Required fields are marked *