If your theme uses wp post class
function post_classes($classes) {
global $post;
$customMetaVariable = get_post_meta( $post->ID, 'customMetaName', true );
if($customMetaVariable == 'desiredCustomMetaValue'){
$classes[] = 'cssClassName';
return $classes;
}
}
add_filter('post_class', 'post_classes');
then in your style.css you could use:
.cssClassName{
background-color: red;
}
hence applying that class to all of the posts that contain your desired meta value.
if your theme doesn’t use wp post class you have to edit the theme to include
<?php post_class(); ?>
ex:
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
//post stuff hurr
</div>
all explained here.
Related Posts:
- How to add an admin function only to posts, not pages?
- Allow role to delete posts but block him the wp-admin
- Limit function to specific post category
- Every second post different class in blog view
- How to change the case of all post titles to “Title Case”
- How to detect single.php (but not single-portfolio.php)?
- How to remove a column from the Posts page
- Update post counts (published, draft, unattached) in admin interface
- Function to execute when a post is moved to trash .
- How to display by default only published posts/pages in the admin area?
- Changing the post date and time with function
- Set Default Listing “View” in Admin
- display all posts in wordpress admin
- Get current post id in functions.php
- Dynamically add id to heading tags
- Is it possible to bold certain words in a post title?
- Sends out email to admin
- disable WP automatically inserted line breaks after an image
- Can I force a metabox to be in one column?
- Add a new post status in the post progression
- Help! Turn php link data into url OR hide edit link in post admin OR hide drafts for all users except admin?
- Getting the post_id in wp_ajax function
- Fatal error: Call to undefined function post_exists()
- Modifying admin sidebar contents to show pending posts indicator
- How to publish a post with empty title and empty content?
- delete post also attachments
- Is this the best (and only) option to style CSS for a given post type?
- Any way to create a revision of a post ONLY with a new button in the Meta Box?
- using slug instead of ID in admin edit post url
- How to call function within a page/post, to dynamically generate content?
- Restrict users from editing post based on the age of the post
- How to Load Scripts and CSS for Admins Only When Editing or Adding Posts
- Modify CSS via Theme Control Panel
- Add “Post Options” for new wordpress post
- How do I use element instead of tags in WordPress post content having webP support?
- Post Admin – Filter by posts without tags
- Add javascript when post is published
- adding a custom css class to post
- Code to auto expire posts after 30 days
- Why does the_date work in the first custom column, but not in the second, in a series of customized Posts columns?
- List only child categories a post is in, of a specific parent category
- Add link on the top menu of the post table?
- Add a special filter link to All Posts in admin
- Keep a fluid max number of posts on site
- which action to hook to in order to perform post-publish action
- How to change post status from publish to draft using hook in wordpress?
- Make “Post published. View post” Open in a New Tab
- Guest Author – How to modify my custom function code if the guest author URL will follow a particular pattern/format?
- Overview with latest edited posts and pages
- Hiding by default specific post status on backend list?
- prevent showing posts of an specific category in admin posts section
- Human Time Diff, change mins to minutes
- How to get new post URL?
- Force update all posts in custom post type, no content changes
- Custom wp_trim_words() function not trimming right
- Remove whitespace at the end of posts?
- Disable REST API for a user ROLE
- How to display post tags
- How to Display Post View Count
- Remove double space after a period
- Add confirmation popup on “Move to Trash”
- Why does `url_to_postid` return 0 when testing `page_for_posts` Page?
- Is there a way to change the color of a row in Post Administration based on the type of post?
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- How To Add Perfect Apostrophe And Quotation Mark In WordPress Posts?
- Add filter-by-tag in the all posts admin console page
- Delete Post From Front-End and attachment permanently
- Hide add new page button
- $post object is null
- How to get a nofication when post submitted
- When paginating a Page with the tag, how can the 2nd and subsequent page styles be customised?
- Function to show random posts from a category
- How to change the page break URL from ../post/2 to …/post/page2/
- Hiding posts in a list from specified categories
- How To Keep Posts from Being Displayed Two or More Times on My Homepage? [closed]
- How can I list random authors from current post category?
- Disable single post page
- Latest 5 posts (custom post type), each post different CSS
- How do I add a custom body class to the admin area of a page?
- Enabling post thumbnails for custom post type
- Adding a text link under the post title in the lists of posts
- Run a function when post is deleted?
- Checking is user author of number of posts?
- Is it possible to change the admin posts per page view?
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- Create cron job without a plugin?
- WordPress Theory Lesson – Image Columns within posts with alignment?
- Getting current post ID in functions.php
- Change default Posts page
- How to rename “Publish” metabox title in post screen
- How to style the last post on the front page different than the others?
- Add a class to post title if a link ends with a certain extension
- Action hook for new pending posts?
- Show info to author only
- Uppercase first sentence in every post
- Add icon/badge next to posttitle of specific category
- Ajax posts filter by date, comments, top views, top likes
- Copying and pasting emoji in a wordpress post
- Prepend or add an Image to the content of a Post
- Converting a dynamic piece of code using WordPress Loop into a static one using Post ID