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.

$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?


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';
  • 2
    I prefer a function-specific test versus the more generic is_admin() when including code to support something like this. if ( ! function_exists( 'wp_terms_checklist' ) ) versus if ( ! is_admin() ) is more explicit and can avoid some unnecessary overhead depending on the code structure. – Lance Cleveland Aug 29 '17 at 21:02
  • Good point, I'll edit the answer. – bonger Aug 30 '17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.