0

I've searched a lot for options like has_category, in_category, get_the_category, but I couldn't make them work

Here's my pastebin

http://pastebin.com/Zi7auvtv

I want this code to run only if the post belongs to the category "destaque"

I didn't put my tries on the pastebin code to avoid being confusing

Some of my tries:

    if (in_category('destaque')) {
    echo 'The content';
    }

    OR

    if (has_category('destaque')) {
    echo 'The content';
    }

But nothing work

And so on, tried a lot more complex too, but no luck

Any ideas?

Thanks!

  • 1
    So this fails even when you know the post has the category for sure? Then something is messing up $post global for you, outside of the code you have shown. – Rarst Jan 17 '14 at 21:54
0

Try in_category again, but also with specifying the post id:

 if (in_category('destaque', $post->ID)) {

     //do whatever you need to

 }
  • Been there, didn't work – Lucas Bustamante Jan 17 '14 at 12:33
  • To clarify, 'destaque' is a term in the default categories and not a term in a custom taxonomy? – MichaelJames Jan 17 '14 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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