meta_key=_jsFeaturedPost
meta_value=yes
I have posts where some have meta keys/values and some don’t. I would like to target the ones with the meta keys that have a value of ‘yes’ and add a CSS class to those posts so I can style them differently.
Ideally, something like: if meta_value for meta_key (jsFeaturedPost) is yes, then add class.
How would I do this?
The
post_class
filter is your friend. Just combine it withget_post_meta()
.Just replace
my-custom-css-class
with whatever class you want to apply to the post container in question.As noted in the comments, this implementation relies on the
post_class()
template tag being called properly in the post container, e.g.:Edit
Re: this question in the comments:
The easiest method is probably to filter
the_content
:Add a very high priority number, so that this filter gets applied last.