1

So I have a plugin, and i want to have a multiselect drop-down list with all categories in widget's settings and store (by admin's choice) selected ones (ids).

enter image description here

Then to check if we are viewing a post "is_single()" and the post has some of the above selected categories "in_category("3") (say we chose cat:Logo with id:3):

if(is_single() && in_category("3")){//do my thing}

and ofcourse if user chose more than 1, say (3,5,6 cat ids(by their names click)) the codition would be something like:

if(is_single() && in_category($categoryholderfromdb)){//do my thing}

Where $categoryholderfromdb="3,5,6" (stored user choices in db (widget settings drop-down))

i've tried to do it, but i can't figure out the part with drop-down multiselect and then "in_category" when checking for multy values.

Can anyone give me example of the above question?Thanks!

4
  • What plugin are you using for the multiselect? And how does it store the data for the post? Commented Apr 3, 2014 at 9:13
  • The idea is to create one function like this one (in the image) i want to create my own. That's the hard part of the question, i need similar working script... Commented Apr 3, 2014 at 15:10
  • Well that's much a bigger question, and outside the scope of this one. Have you tried the WordPress codex/Google/WPSE for advice on creating metaboxes and saving data? Or the much easier alternative Advanced Custom Fields plugin? Commented Apr 3, 2014 at 16:03
  • I've already developed the widget, i just need the multiselect box and the "in_category" codition that's it. Commented Apr 3, 2014 at 16:05

1 Answer 1

0

You want the function in_category(), not in_cat(). And to check multiple categories you need to pass an array as a single argument (as opposed to multiple arguments):

if ( is_single() && in_category( array( 3, 5, 6 ) ) )
1
  • yeah i know it is is_category i've just mispelled it. The idea is to have the cats in multiselect and then retrive them into an array maby? and then to use it in tha bove example. I've edited my question, please take another look. Thanks Commented Apr 2, 2014 at 19:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.