Not sure if this is a bug or me doing something wrong.
I am querying a specific post type and want to only specific posts ID. For this I am using the shortcode option as you can see in the screenshot below:
Tried using a different shortcode that just returns a hardcoded post ID and I am getting the same error on the front end:
add_shortcode('am_module_id_hardcoded', function ($atts = "") {
return array(8494);
});
Error:
Warning: Array to string conversion in /public_html/wp-includes/shortcodes.php on line 355
Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, string given /public_html/wp-includes/class-wp-query.php:2191
If I’m reading this correctly, then shortcodes shouldn’t be used as a dynamic value for “Include Posts” in the Query Editor because the shortcode will always return a string and a string cannot be fed to the WP_Query’s “post__in” attribute (AFAIK).
A better option would be to use a function instead of a shortcode. But unfortunately this isn’t currently available in the Query Editor (I’d love for this to be available everywhere. I might submit a feature request).
I need to figure out a way to work around this… if you have any suggestions, I’d love to hear them.
To achieve what I need, I changed the implementation of the “shortcode” dynamic value implementation in the Query Editor (dynamic_query API) to interpret the key as function name instead of shortcode name:
Of course, changing Cwicly code like this is far from ideal as any change will be overwritten by an upgrade. Also, this breaks using shortcodes generally in the Query Editor (which I am not using for anything else) But this solves my problem temporarily.
@Louis , I could write and submit a proper patch to add support for “Functions” for dynamic values in the Query Editor if that’s something that you’d accept. Otherwise, I will submit a feature request.