I believe your issue is with $vals=get_post_meta($post_id, $key2, true);
If you check the codex, the last parameter for get_post_meta is whether to return a single value or array of values. You have set it to true
which means return only one value.
Try it with false
(the default) it should work.
Related Posts:
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Alter secondary loop to exclude posts from current page category
- How to get to a specific position in wp_query?
- have_posts() execution failure
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to get post ID in a Page?
- Display an image if odd number of posts in grid
- How to add div blocks after certain set of post
- How to overwrite orderby with add_query_var
- get_the_ID() in the footer returns wrong value
- Get all posts as an array ID => Name
- WP_Query multiple post results
- Do not duplicate posts with multiple categories in multiple loops
- Infinite Loop – WP_Query
- Dividing the loop to style post differently
- How to extract information from a wp_query result?
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- Wp Query : Order by distance lat,lon
- in_array not working on dev server but works on localhost
- How to display sticky post always at the top (before regular post) in wordpress?
- Making list of posts with chosen description
- My query keeps looping infinitely ! how to stop it?
- Efficient way of querying for a “fallback” post?
- For each 3 posts, show a different post type
- Add post class in custom loop (WP_QUERY)
- Create a hierarchical loop at predefined markup requirements
- Advanced Taxonomy query, with 3 post types
- Why does a meta_query break this WP_Query?
- WordPress post pagination on custom template not working
- Pagination in category.php not functioning
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- How do I exclude the current post from the upcoming post query
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- Best Practice for PHP
- Print html when custom field has value inside while loop
- how to display active, upcoming and past event with featured listing with pagination
- WP_Query sort using multiple numeric meta values
- Facebook “like” open graph meta in header.php
- WP_Query loop, does not display special characters in title correctly
- Remove query string specific key value
- Blog posts repeat
- Checkbox doesn’t stay checked, conten
- Create a Blog Template Page
- Add content after the first post in WP Loop
- Exclude posts with specific metadata from search?
- 2nd page displaying the exact same posts as my first page (minus the very first post)
- Is the 404 page automatically displayed if a loop returns nothing?
- Why doesn’t PhotoSmash plugin play well with wp_query?
- How to show meta value code HTML after x paragraph
- How to pass a variable to get_template_part that’s updated every time the template part is called?
- Form search query – displaying ACF “Post Object” field as results
- get_the_ID() doesnt work
- change the default order of posts only for specific categories
- Calling function in loop causes repeat data
- How can I split my query result in 2 arrays?
- How to get post category list as select in front-end?
- Order a WP_Query by meta value where the value is an array
- How do I check if there is a tag in the title
- How to Generate a list of Most Commented post?
- How to pick “full/thumbnail” images in the loop?
- How to Fix an Archive.php That Displays All Posts?
- How to add ASCII symbol after each recent post [closed]
- Using multiple variables to assign categories to an array
- WordPress Search Ajax + Isotope + InfiniteScroll
- How to call my PHP function with AJAX ? wp_query
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- Accordion headings cuts off to second line on collapsing a accordion heading (used acf repeater)
- ACF background-color per post in a WordPress loop
- Advertisement in Loop Posts wordpress
- How to display last whole post on the homepage
- wp_query beginner
- Adding custom PHP to existing loop in Genesis
- How to Pass Current Taxonomy Terms into new WP_Query?
- WooCommerce – Print Processing orders [closed]
- Loop returns more items than exist?
- Modify category archive page loop on functions.php
- WP_Post is not from correct array
- List of child pages fetch next results at link click
- Limit ads appearing more than three times
- How to get category pages to look like a certain archive page?
- Pagination on Custom Loop
- Post Title Not showing up
- reorder a WP_Query, using a dropdown
- Custom single.php files for different post formats
- Custom query_posts() parameter
- Troubleshooting “loopback requests that take too long”
- How to modify this function to exclude also the post belonging to a specific category?
- Help with if/else loop [closed]
- Display biography post for today’s birthday person
- Variable ++ in query loop
- a problem in class in class-wp-hook.php
- Count custom posts type and filter by tag
- AJAX WP_Query’s order and orderby parameters not working