Try:
$rating = get_post_meta($post->ID, 'ratings_score', false);
var_dump($rating);
You will notice that you get an array, even if your ratings_score is 2. To wit:
array(1) {
[0]=>
string(1) "2"
}
That will never equal 2 so your condition will never work.
The third parameter of get_post_meta() if set to true will collapse that array to a scalar, and that will work.
$rating = get_post_meta($post->ID, 'ratings_score', true);
var_dump($rating);
Note that if your post has multiple ratings_scores you will only get one of them and it may not be the one you want.
To make this work with multiple ratings_score entries use:
$rating = get_post_meta($post->ID, 'ratings_score', false);
if (in_array(2,$rating)) {
echo 'found it';
}
Related Posts:
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- Get ID of a page containing secondary loop in content
- How to add “time” data this?
- Next and Previous loop
- How to hook into container
- Output meta into arrays
- Sending mail not working correctly
- using update_user_meta to rank users
- get_post_meta printing empty fields, but it shouldn’t be
- Check value of post meta within IF statement
- Best way to check if a post with specific meta exists
- WP update_post_meta link loop
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- Display articles related to a custom field on a page
- Showing sticky posts with get_posts()
- single.php – how to mark current page in the loop
- Cannot retieve the_content() and the_author() – both returning empty strings
- Get post id within comments loop
- How to order by multiple fields using standard query_posts?
- Get 1 more post in loop
- Pagination not working in category listing [duplicate]
- Make loop alphabetical
- How to check if a product is purchased within the last 365 days before displaying something
- How to append a query string to pagination?
- For each loop on every word in post
- Display name of taxonomy once
- Use have_comments() for current post instead of last post in loop
- Displaying the first, second, and third posts from a category in separate slides
- Get the image src and href data from posts
- WordPress shortcode in content, output in sidebar?
- Using variable in WordPress loop as criteria
- WordPress Alphabetical Sort Loop Issue
- Get_template_part() problem with the_content()
- Frontpage pagination by week
- Integrating WordPress with Your Website
- Multiple instances of Featured Image Thumbnail As A Background On Homepage
- Altering “posts_per_page” for defaut loop
- Why doesn’t ‘continue’ work in page?
- Fetching posts from wordpress function in ajax
- Remember the Meta Value With Radio Buttons
- Saving return value from the_author_posts_link()
- Accessing the Posts page Content
- how to run loop in function.php that sends email based on specific conditions?
- Query post & loop problem.
- Exclude current post ID from loop in sidepbar.php
- loop inside a loop : search for posts in the same category
- How to sort a loop after most viewed
- How do i create a loop that list and divide posts into months?
- Forcing page to top of the list when using get_pages
- How to declare a variable in a loop and make it available in the template file
- WordPress posts loop not displaying all posts on blog
- get_page_by_title not working inside fucntions.php
- How to use single.php output in function.php
- Duplicate posts on archive page
- Bootstrap tabs are not being clicked in WordPress loop
- Get gallery in loop through ajax
- Get a specific size from wp_get_attachment_image_src
- Loop random posts and display odd and even based on two alternating meta values?
- WordPress + Isotope: how to give different widths to each entry?
- hide woocommerce tab if empty
- Get top Page IDs from menu and cycle through their child pages on a scroller
- How to manually define the primary loop
- Url outside the loop
- How to filter get previous post function by meta value DESC and post date DESC?
- Show other category posts in single.php
- Why does it loop twice?
- Cant pull in featured Image
- Custom Looping of WordPress Posts
- how to place Post and page content side by side
- Add specific class to featured posts
- Get meta value when the page is a blog archive
- Echo Most Recent Sticky Post in Loop?
- Link Button url count php and wordpress
- ACF field not appearing correctly in loop
- Posts are being displayed from old to new, in ascending order
- Loop in taxonomy for terms and post
- WordPress Tags in class
- Set loop format & have a loop inside other one
- Need a conditional to test if title of parent page matches title of child page
- Query counting excluded category on paged loop
- Using shortcode within shortcode with dynamic variable
- modify default HAVE_POSTS() Loop without inserting new variable (i.e. $loop->HAVE_POSTS)
- Why is my pagination showing up?
- Changing the loop w/o killing category links
- Custom loop page with post navigation
- Pages with a loop (index, archive) are loading the first image as post_thumbnail
- the loop – how to control whether wp or plug-in runs it
- Randomly Display One Image From a 10-Image For Loop
- An action that runs after each post in the loop on index/archive page?
- Modify my code – which takes the first sentence of the post and use it as a h2 tag – to work outside the loop
- How to show only specific tag in wordpress loop
- Getting post id in for loop
- Different style for first two (sticky) posts
- WooCommerce – Checkout suddenly stops working [closed]
- WordPress loop put title into variable
- How do I display 3 post each in a bootstrap carousel?
- Multiple loops using next_posts_link & previous_posts_link
- Want to images load first then title in WordPress loop
- How to add a continuous number to HTML tag attribute value inside The Loop [closed]
- WordPress Not Sorting By Custom Field