0

i.e [test somevalues=1,2,3,4,5]

First time poster and alsoa php newb, I'm trying to add a feature to a plugin but I seem to keep triggering a debug notice from wordpress.

$somearray = shortcode_atts([
               'somevalues' => null,
    ], $atts);
$somearray['somevalues'] = array_map( 'trim', str_getcsv( $somearray['somevalues'], ',' ) );

The above does work, but it results in a debug Notice: wpdb::prepare was called incorrectly.

Is there a way to achieve the same without triggering the notice? It doesn't have to be csv, I just need it to return a string of somevalues, rather than returning an int. I guess what I want it to act like is as if it was written like [test somevalues=one,two,three,four,five]

Edit: Found original stack post from 3 years ago which is exactly what I'm trying to achieve Retrieve multiple values passed to a single attribute in a shortcode

Any suggestions on how to get around this? Many thanks

5
  • Please show your full code, it's not possible to see how that error is triggered, in the code you have shared. Commented Jan 30, 2021 at 12:58
  • So you're just asking how to convert the string "1,2,3,4,5" into an array by splitting the string on commas? Commented Jan 30, 2021 at 13:50
  • I'll see to sharing a large chunk of code or a fully working demo piece. @Rup, yes something like that, the issue I'm facing is if I leave the input to somevalues from the shortcode as is a user can put in 1,2,3 but the array will only see the first value 1 and discard the rest due it treating the key as an int. Commented Jan 30, 2021 at 18:49
  • This might help: wordpress.stackexchange.com/a/42526/7968 and I guess you based your code from here:wordpress.stackexchange.com/a/269660/7968 which seems to be a working example, so I would read that again carefully. Commented Jan 30, 2021 at 21:28
  • @Q Studio, Thank you, you prompted me to go and check line for line took hours, I was passing multiple arguments to $args within a single attribute that turned out to be part of another plugin which was causing the notice, I changed the key in $args and it stopped, so it was a conflict. Commented Jan 31, 2021 at 12:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.