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
  • 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, 2014 at 21:54

1 Answer 1

0

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

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

     //do whatever you need to

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

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.