Learn how to fix an issue with not displaying labels for archive pages. Method is actual if you are using some filtering plugins.
This article is for those experiencing issues with displaying labels on archive pages.
The solutions described here will be particularly useful for those using filtering plugins, especially the WBW Product Filter plugin, but they may also apply to other filtering plugins.
Even if you don't have a filtering plugin installed, you can try the methods described here. The issue is related to the Advanced Woo Labels core query modification, which can result in labels not being displayed. If you have any plugin installed that could potentially alter custom queries, please try the solution provided below.
The problem stems from an empty label ID array after executing the get_awl_labels
function, which runs a custom query to return all available shop labels.
Third-party plugins can modify these queries via related hooks, potentially leading to empty array results.
To solve this, we will use the awl_get_labels
hook to filter label results. If the array is empty, we will retrieve all label IDs via an SQL query.
Here’s the code snippet to use:
add_filter( 'awl_get_labels', 'my_awl_get_labels' ); function my_awl_get_labels( $labels ) { if ( empty( $labels ) ) { global $wpdb; $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'awl-labels'"; $results = $wpdb->get_results( $sql ); $posts_ids = array(); if ( !empty( $results ) && !is_wp_error( $results ) && is_array( $results ) ) { foreach ( $results as $search_result ) { $post_id = intval( $search_result->ID ); if ( !in_array( $post_id, $posts_ids ) ) { $posts_ids[] = $post_id; } } } $labels = $posts_ids; } return $labels; }
After adding this code snippet, check your archive pages. If the issue was caused by the problem described, the labels should immediately appear on those pages.