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 detect single.php (but not single-portfolio.php)?
- disable WP automatically inserted line breaks after an image
- 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
- delete post also attachments
- 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
- Add link on the top menu of the post table?
- Add a special filter link to All Posts in admin
- 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?
- Hiding by default specific post status on backend list?
- prevent showing posts of an specific category in admin posts section
- How to display post tags
- WP_Query in functions.php overrides global $post object, even with wp_reset_query()
- How can I list random authors from current post category?
- Disable single post page
- How do I add a custom body class to the admin area of a page?
- Enabling post thumbnails for custom post type
- Remove the Edit button in posts for permalinks on certain user roles? WP 3.3
- Action hook for new pending posts?
- 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
- Why content_arr[‘extended’] removes paragraph tags?
- Style Differently Edited Posts
- How to display the link (title) and thumbnail post?
- CSS: How can I show a photo beyond the template’s column, but contained within the browser window? [closed]
- How to do set post permalinks using 6 digit random unique function?
- Can I search posts and pages for css classes?
- Prevent additional top level categories but allow more children
- Publish post’s date is set to Nov 30 -0001
- Admin – create custom post status and display above table
- WordPress Automatic Filename Changer
- How to add tags (custom taxonomy) to post class css?
- plugin to post from admin to flickr [closed]
- All Posts admin screen – show time underneath the ‘Date’?
- Get post ID in post/page edit area
- Is there a way to specify an extra class for a post or page with no title?
- disable Tab post on nav-menus page (Admin)
- Adding bootstrap classes to video shortcodes
- Make a vertical dynamic list of posts in alphabetically order and in columns [closed]
- How to remove specific tag from multiple posts?
- How to detect when admin user is on the All Posts page?
- How to make different custom post layouts?
- Get post meta retrieving wrong value
- The_excerpt() doesn’t parse – how to change that?
- Add custom text automatically on each post
- How to add convenient buttons for new custom post statuses
- My Custom Post Type Still Using index.php
- Getting Whitescreen when publishing a post [closed]
- Un-highlight Blog Menu Item when Category Menu Item is Selected
- Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )
- add div after image in post [closed]
- Related Posts: Changing Function For Posts Per Page
- How do I switch css class on post
- Same post appears in related Posts?
- Locally change the font family [closed]
- YARPP php question
- Right align a youtube video
- Help on conditional statement to accompany wp_insert_post function please?
- Set Default Post as Parent Child (Nested) Relation
- How to allow arbitrary inline CSS in posts?
- how to show comments only author which send own posts in wordpress
- get category in list of posts // shortcode for custom related posts
- Alt text attributes not showing over portfolio images
- Css and function issue on author archive page
- WordPress Recent Post with the badge “New” on the side of the title post
- Set a post expiration and delete a post when expirate
- Put page on Archived statut after end of publication date
- I have two post types in the same query, how can I use CSS to select only one post type?
- Replace Tag Keyword With Link Within Post Content
- Excluding tag Link from html tags in Post content
- Get post id outside loop : Notice: Trying to get property of non-object
- im trying make a function to auto correct posts when i open the posts in the backoffice
- How can I alternate styling of images in a post? [closed]
- issue in wordpress auto delete post and redirect to another 1
- How to change number of posts shown on homepage vs other pages?
- Show only top 3 posts from 3 categories in order on home page
- Background image in posts
- How to get posts from network blog
- Get post title by Alphabet
- How can I create a menu items from meta box based on users input
- How to use wp_editor(); in functions.php then retrieve content in the template
- Choose options via url
- How *not* to show the last post on the latest posts list
- save_post not working
- wp trim function not working
- Insert Shortcode exactly at the end of the content
- Change a div background color on Post ID
- display last post modified date in genesis child themes
- What function does the loop of displaying posts?
- Custom Post-Rename Function Does Not Function in WordPress 6.x
- How to sort posts alphabetically based on a specific parent category
- posts blocks don’t show up correctly