I had a search page where the user can filter the results by taxonomies. The client asked to add filtering by content type. I thought it would be easy, but it kept giving me "array to string conversion" errors. The checkboxes are configured with name="taxonomy[]" in order to pass multiple values.
It was late and I ran out of debugging steam, but it wasn't working just using the array, but it worked by imploding it and then exploding it so I went with that.
I'm pretty new to Wordpress and I'm a bit unclear how I keep this change in my filesystem without it being overwritten every time there is an update so I'm hoping this issue flag can help lead to a long-term fix to the plugin. Super happy to help, hit me up if you have any questions.
diff --git site/web/app/plugins/wp-extended-search/includes/class-wpes-core.php site/web/app/plugins/wp-extended-search/includes/class-wpes-core.php
index ad4326ca..9cdb5acf 100644
--- site/web/app/plugins/wp-extended-search/includes/class-wpes-core.php
+++ site/web/app/plugins/wp-extended-search/includes/class-wpes-core.php
@@ -283,8 +283,13 @@ final class WPES_Core {
// Set post types.
if ( ! empty( $this->wpes_settings['post_types'] ) ) {
- if ( isset( $_GET['post_type'] ) && in_array( esc_attr( $_GET['post_type'] ), (array) $this->wpes_settings['post_types'], true ) ) {
- $query->query_vars['post_type'] = (array) esc_attr( $_GET['post_type'] );
+ $attr = isset($_GET['post_type']) ? $_GET['post_type'] : false;
+ $attr = is_array($attr) ? implode(',', $attr) : $attr;
+
+ if ( $attr && !is_array($attr) && in_array( esc_attr( $attr ), (array) $this->wpes_settings['post_types'], true ) ) {
+ $query->query_vars['post_type'] = (array) esc_attr( $attr );
+ } elseif ( $attr && is_string($attr) ) {
+ $query->query_vars['post_type'] = (array) explode(',', $attr);
} else {
$query->query_vars['post_type'] = (array) $this->wpes_settings['post_types'];
}