You can try to add global $post;
on top of your code. But it depends on where the function is called.
Related Posts:
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Can’t publish custom post type – “You are not allowed to edit this post.”
- Custom fields for custom post type
- Show future events based on custom field AND order by date
- Meta Data for Custom Post Type not saving
- Using preg_replace to filter custom textarea
- Check if post with same meta value exists
- Filter date from post meta when date is in string format
- Get only used meta_values
- If Post Meta Equals Current Title Conditional Advanced Custom Fields
- Is there a way to exclude posts based on meta_values?
- Archieve.php not loading for custom post type
- Submitting Custom Post Types with custom fields from Front-end form
- create custom meta box with default value
- retrieve permalinks of posts inside custom post type by using post ID
- Get $post->ID from a URL
- Displaying a div from an assigned meta_value when on a page
- Meta data (Tags and Categories) for Custom Posts not showing.
- Display different information of a custom post type
- Create Array from custom post type to display a slider
- Setting Post Title via Meta Data returns Auto-draft
- How to Echo Metadata Value in Currency Format
- Issue on Working with Metabox – Checkbox to enable Sale Items
- Filter posts by tax (dropdown) and meta value
- delete_post_meta() for whole CPT / multiple posts?
- How to get specific post meta by title or id
- Publish and save specific postmeta to a filtered post_type
- How to move a post to different post type with all meta data?
- Why do I have to press the “Update” button twice to save my meta box values?
- How can I display a drop-down select of Post Names
- how to show records that don’t have custom meta value
- WP API Response does not show my registered metadata
- How to detect that the save_post hook is calling the callback associated to the current edit post page only
- post_type internal ID?
- $post->post_meta not pulling any post in wordpress/php
- Values from meta-box not on $_POST
- WP_Query of custom post type sorted by meta_key has unexpected results
- Returning a custom content types with meta values
- Custom post type suddenly stoped working after WordPress 5 update
- Batch Extract Date from post title and put into ACF custom field
- copy images from custom field to another custom field
- How to show custom field on specific custom post type posts only when filled
- How to handle this specific case of custom post type?
- Save CTP post meta different values each day without overwriting previous values
- get_post_meta returns NULL in front-end, but correct result in back-end
- Cannot obtain custom meta information
- Problem with adding custom post type meta to header by plugin
- is_main_query() never called on WP 4.4
- How can I output WPAlchemy repeating fields meta values in my page template?
- Meta box data is saved but NOT displayed in the meta box text field. Why?
- How to call a post’s metadata in shortcode.php?
- Custom post type returns bad post ID
- Save Metabox Custom Field Value
- Echo custom post meta from options array
- Value of post meta dropdown is not showing in WordPress
- Meta box data not saving
- Get all metadata for a given custom post type
- WP_Meta_Query object with conditionals
- Trying to write shortcode with get_post_meta but isn’t working
- Related posts meta_query CPT
- Give a unique ID while saving
- Meta box with front-end styling
- Sanitaizing Select Optin For Custom Post Type Metabox in WP
- How can I get some of a posts meta data whilst it is still inserting?
- How to retrive Custom Post Type Meta Fields in Custom WP_Query
- Advanced custom field – posted fields from custom post type
- Cannot Save MetaBox Data in Custom Post Type
- delete duplicate meta_value with same post_id
- HM CMB: Post Select Field for CPT ID
- Search CPT Title AND Meta
- Getting WordPress to store 0 values for custom post type meta
- updating one custom meta field only
- Add a class to post_class if more than one post shares same meta_value_num
- Function to return values from metabox
- Add a meta field to the list of results for a custom post type
- best way to use custom taxonomy, post type and meta in a job system
- Empty meta-box returns publishdate if no value is set?
- Say I have a tech blog, how best would I store technical specs for a phone, if i use custom post types
- Building tags and archive using meta from custom post type
- How to order custom posts by one of the custom fields value, ‘date’?
- Problem Saving Custom Post Type Meta Values
- Use Author Ids or Names to echo different output inside loop
- Filter search posts by post meta?
- Custom Meta Box with variable number of fields
- Custom fields for post or terms which don’t update on post update
- Hide title field of selected post-types on edit pages
- WordPress CPT Taxonomy Dashboard Search – How to include taxonomy in search?
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Should I use a custom taxonomy or custom post type for grouping a list of panels associated with a group of tests?
- How to create review point system for CPTs (many-to-many relationship)
- After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
- Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
- Get_post_custom not fetching value from array wordpress
- Add a form in every post and save data in post meta
- How can I write a function that would update any missing specific post metadata?
- SELECT custom post type and its meta in SQL
- How to use multiple Meta Field from CPT as Post permalink
- Save data is post using php front end
- How is possible to know ID of taxonomy-{taxonomy}.php page for ACF fields
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field