If you’re inside the while
loop, use get_the_ID().
// returns an array as this is a multicheck field in Magic Fields 2
if(get_post_meta(get_the_ID(), 'services', true)){
$services = get_post_meta(get_the_ID(), 'services', true);
$services = maybe_unserialize($services);
// foreach item in the array
foreach ($services as $service) {
if ( sanitize_title($service_title) == sanitize_title($service) ) {
echo '<p>' . esc_attr($service) . '</p>';
}
}
} else {
//No services set
}
Check this.
Btw, you can set an array as a meta field value (but via code using add_post_meta, not the via post meta box on post edit screen).
Related Posts:
- How to only display posts whose meta_value field is not empty?
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- WP_Query with meta_value LIKE ‘something%’
- Sorting meta_value as integer doesn’t work
- Add a default meta_value to new posts
- Ordering by meta_value AND date NOT WORKING with wp_query
- How to use Meta Value Compare in WP_Query For Max and Min numbers
- meta_query works locally but not on live server
- Ordering Posts Type A by Custom Fields of related Post Type B
- Custom query for sidebar isn’t returning results
- Need wp_query to return all children and grandchildren
- new WP_Query to get max price meta value not working
- Query multiple meta values
- Why isn’t my `meta_query` array functioning properly?
- How to orderby multiple meta fields if some fields are empty
- Meta_query on same meta key, with diffrenct values
- How to extract specific post
- Meta Query relation “AND” then set array accordingly
- Does meta_value (array) work with ‘orderby’?
- WP Query Meta Value – How To Identify Specific, Unique Values?
- query post by author gender
- Show posts of an advanced search form
- Meta query with compare by more than 2 fields
- Order (by ASC) posts with meta_key so posts without values are last
- Save queried result into database
- WP_Query multiple value not working
- Gather same custom field values in one value in a select tag with wp_query
- Order posts by more than one variable (meta_key and publish date AND time)
- how to query for meta_value have array
- Sorting Posts with meta value not working
- Cannot order by in WP_Query
- Query to get all the posts of more than 2 meta_value having same meta_key?
- Order by meta values
- query_posts, oderby meta_value & print “future” posts
- Get posts by meta value except one post [closed]
- why ignore_sticky_posts in sticky post query
- WP_Query by post ID doesn’t work if post is in custom post_status
- Tracing the life of a query
- WP_Query orderby taxonomy term value (numeric)
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to get post meta value and post in one query?
- Get the post permalink within the loop but without additional DB query
- Pagination 404 errors for author posts query on author.php
- How to show recent and upcoming birthdays using meta_query
- How to change posts order on Category and Tag archives?
- How can I retrieve comments from last 5 minutes for a post?
- Create a sitemap without a plugin – get parent pages only?
- WP_Query on custom field and order results
- WordPress: Display posts by custom select query
- Get ONLY the number of results in a query
- Include custom field in Ajax search WordPress
- Inserting serialized value into wp_postmeta using update_post_meta
- Display custom field meta outside loop, site wide
- Where is the WP_Query instance instantiated (when working with themes)?
- Iterating through $wpdb query without using get_results for large query results
- WordPress ignoring LIMIT / posts_per_page despite being in wp_query
- Conflict with get_posts and the_content
- Custom query with meta_key not working fine
- Can I simplify in function column_default use of queries
- How to provide meta_key array to wp_query?
- wp query error while paging the posts
- Highlight post in sidebar on single page
- Specify strict ‘order by’ in WordPress query
- Single field to search for matches on post ID or meta values
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- Using post_where filter only on main query NOT sidebard new WP_Query
- How to avoid bypass of search bar rules?
- Slider won’t work with custom query
- wordpress udpate query not equal to
- How to generate feed for custom template
- WP_Query with one category in args shows other categories
- WP Query – filtering terms with regex
- Excluded category from loop
- Add content depending on page loaded
- Custom template for password protected page
- Having a variable based on $post_count increase when i move to the next page of results
- Post order by custom fields
- WP Query and multiple pages
- How can I do a orderby by the number of items? So basically list by starting with the array with the largest number of post
- How do you do a meta query on an encrypted field?
- meta_query with meta values as serialize arrays
- Multiple WP_Query args combinations according to post type
- wp_set_object_terms() custom taxonomy not working correctly when using insert post
- in_the_loop() issue with custom query
- How to restrict add media library only to images of the same post family?
- Is my code correct?
- Wp Query sort order
- get_posts query caching?
- wp_query returns match with no criteria
- pre_get_posts with WP_Query to prevent posts from specific tags
- How can I modify standard search query to include also ACF custom fields values?
- Retrieving category pages from subcategory returns empty sets
- Loop through multiple custom fields with increasing number
- Different number of posts showing in development vs production server
- Order WP_Query results in order other than ASC or DESC
- More efficient query to display posts in same sub-category?
- Get post closest to today
- Pagination in custom query not working [duplicate]
- $query_args for loop to only get posts from “current category”?
- Display post format post in the sidebar