public static function display_wp_list_categories_item_helper( $matches ) {
global $kn_display_wp_list_categories_wpdb_results;
$string_key_value = $kn_display_wp_list_categories_wpdb_results[ $matches[1] ]->meta_value;
return str_replace( '<span>', '<span>[ '.$string_key_value .' ] ', $matches[0] );
}
public static function display_wp_list_categories( string $output, array $args ) {
global $wpdb, $kn_display_wp_list_categories_wpdb_results;
$tax_and_acfkeys = Datamodel::get_taxonomy_term_acf_keys();
if( ! isset( $tax_and_acfkeys[ $args['taxonomy'] ] ) ) {
return $output;
}
$sql = $wpdb->prepare( 'SELECT term_id, meta_value FROM '. $wpdb->termmeta. ' WHERE `meta_key` = %s AND term_id IN ( SELECT term_id FROM '. $wpdb->term_taxonomy. ' WHERE `taxonomy` = %s )
', $tax_and_acfkeys[ $args['taxonomy'] ], $args['taxonomy'] );
$kn_display_wp_list_categories_wpdb_results = $wpdb->get_results( $sql, OBJECT_K );
$line_regex = '~<li data-id="(\d+?)">(.+?)value="(\d+?)"(.+?)<span>(.+?)</li>~';
return preg_replace_callback( $line_regex, [ 'self' ,'display_wp_list_categories_item_helper' ], $output );
}
Leave a Reply