WordPress category check

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

Read More

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!

Related posts

Leave a Reply

1 comment

  1. 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 ) ) )