$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>errors - Call to undefined function wordpress listing_categories|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

errors - Call to undefined function wordpress listing_categories

matteradmin10PV0评论

What is wrong with this 2 lines? im getting Call to undefined function fw_ext_extension_get_listing_categories()

    $categories = fw_ext_extension_get_listing_categories ( $atts['cat'], 'models' );
$sort_classes = fw_ext_extension_get_sort_classes ( $posts->posts, $categories, '', 'models' );

Thanks in advance.

EDIT: Here is the function

/**
 * @param int|array $term_ids
 *
 * @return array|WP_Error
 */
function fw_ext_extension_get_listing_categories( $term_ids, $extension_name ) {

    $args = array(
        'hide_empty'    => true
    );

    if ( ! empty( $term_ids ) ) {
        if ( is_numeric( $term_ids ) ) {
            $args['parent'] = $term_ids;
        } elseif ( is_array( $term_ids ) ) {
            $args['include'] = $term_ids;
        }
    }

    $ext_extension_settings = fw()->extensions->get( $extension_name )->get_settings();
    $taxonomy               = $ext_extension_settings['taxonomy_name'];

    $categories = get_terms( $taxonomy, $args );

    if ( ! is_wp_error( $categories ) && ! empty( $categories ) ) {

        foreach ( $categories as $key => $category ) {
            $children                     = get_term_children( $category->term_id, $taxonomy );
            $categories[ $key ]->children = $children;

            //remove empty categories
            if ( ( $category->count == 0 ) && ( is_wp_error( $children ) || empty( $children ) ) ) {
                unset( $categories[ $key ] );
            }
        }

        return $categories;
    }

    return array();
}

/**
 * @param WP_Post[] $items
 * @param array $categories
 * @param string $prefix
 *
 * @return array
 */
function fw_ext_extension_get_sort_classes( array $items, array $categories, $prefix = '', $extension_name ) {

    $ext_extension_settings = fw()->extensions->get( $extension_name )->get_settings();
    $taxonomy = $ext_extension_settings['taxonomy_name'];
    $classes            = array();
    $categories_classes = array();
    foreach ( $items as $key => $item ) {
        $class_name = '';
        $terms      = wp_get_post_terms( $item->ID, $taxonomy );

        if ( ( ! empty( $terms ) ) && ! empty ( $categories ) ) {
            foreach ( $terms as $term ) {
                foreach ( $categories as $category ) {
                    if ( $term->term_id == $category->term_id ) {
                        $class_name .= $prefix . $category->slug . ' ';
                        $categories_classes[ $term->term_id ] = true;
                    } else {
                        if ( in_array( $term->term_id, $category->children, true ) ) {
                            $class_name .= $prefix . $category->slug . ' ';
                            $categories_classes[ $term->term_id ] = true;
                        }
                    }
                    $classes[ $item->ID ] = $class_name;
                }
            }
        //if no terms
        } else {
            $classes[ $item->ID ] = '';
        }
    }
    return $classes;
}
Post a comment

comment list (0)

  1. No comments so far