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
- Jquery Slider for profile template
- Retrieve each widget separately from a sidebar
- Should I use loop in the single.php file?
- wp_list_categories: get latest featured_image of category
- Where should I use post_class()?
- Landing Page – Redirect Loop?
- get_the_foo() in the loop – does it perform another query?
- Exclude filter on front page
- Is it possible to display previous post revision?
- Check if date of post is yesterday
- Exclude first 2 posts with meta_key from loop
- Fix inefficient loop breaks post.php on form submit
- Make a custom loop inside single.php with pagination
- Why do I get `Call to a member function have_posts() on a non-object `? [closed]
- Get Pagination (WP-PageNavi) not to work
- Filtering The Loop For Single Page and Blog Page
- the_content() seems to block my ACF-code
- Pulling current post/page data into header.php
- Loop and Page template : my WP_query don’t take args
- How to split a loop into two columns
- Category Ajax call
- Transient loop issue
- popular post weekly and monthly
- WordPress Loop inside Loop?
- Get single post from tags array
- Duplicated posts on category page
- WordPress loop: exclude if it is the latest post
- Apply an Incremental Counter in an Array Function
- Get all posts including sticky ones with get_posts(),setup_postdata(), and foreach loop?
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- Latest Post Styled Different Than other Posts
- WordPress: Loop Help
- Woocommerce: How to display product price [closed]
- Enabling users to control custom loop’s query
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Add “showing posts x to x of y” in custom post type paginated loop
- How do I get my loop.php to properly paginate?
- Custom loop ordering not working
- First archive page with a few posts
- Loop through ACF taxonomies and output associated posts
- How to get user ID’s from multiple usernames?
- How to display first post
- Query posts only with actual text content (not including shortcode or images)
- CPT while loop not working
- Problem with Front-Page.php loading recent posts
- Default featured image set as background image [closed]
- Breaking up the results of a loop
- Where to add offset?
- How to synchronize The Loop with the max post per page?
- How do i create a list-posts-page?
- Exclude posts based on an array
- Is file_exists() compatible with timthumb.php? [closed]
- List ALL posts by author on author archive
- How can I sort my loop based on meta data, using a form?
- Using is_page_template inside loop
- How to add custom checkboxes from loop to WooCommerce product variation options?
- Archive: Lists itself
- Please tell how to stop the category from showing up on posts
- How to show the last article in a different way in my blog?
- Can’t limit posts_per_page in loop
- Slug is changing when I use WP_Query in a metabox of a post
- how to get author comment inside the loop?
- How to create loop in custom page, and get id from url into this loop?
- How to fix pagination for custom loops?
- Check to see if a field is within an array in twig
- Custom loop not working in singular.php, working in other pages
- Archive sorted by month – separate
- One page loop issue with posts
- Can’t print out returned value
- change the_content images for different sizes (Desktop, tablet, mobile)?
- Building theme so user can change header image [closed]
- Get query result before posts are displayed?
- WordPress Group By Problem
- Home page loop with pagination problem
- why get_post_meta is returning 0?
- WooCommerce custom loop pagination on front page
- Eliminate duplicates in a foreach loop [closed]
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Problem with ms-thumb-frame-selected class in Master Slider
- I want the first post on my home page to be lengthier than the rest (example included)
- Loop with Custom Post Type Taxonomies and Interstitial Code
- Question about custom plugin
- loop mix my child-category and parent-category
- How can you make it so the comment box shows on some pages or posts but not all?
- How to get files from loop for zip