you need a global $post;
within that function before trying to access the contents of $post.
Related Posts:
- How to get Custom Post ID by adding filter to child theme’s function
- How to change “Draft” string for status of custom post type to “Unavailable”?
- Custom post status not working
- White screen error for a custom theme
- How do you output custom code between posts in the loop?
- Check Title Unique Or Not and If not error message and dont save
- How to customize a permalink (URL) structure?
- Cannot save CPT meta box
- Allow users to create posts without logging in?
- Custom Post Type & Custom Menu Walker to append custom class for active post types
- Add an Outside Wrapper to my Header and Make it Full Width
- Custom post type’s posts are not showing anywere but in xml sitemap
- post_content is stripping HTML when adding a new post? [closed]
- Post visibility option to theme front-end for author to select?
- Function to add custom HTML into head in custom post-type list page
- Custom Form / Search with Custom Post Type Data
- Stored meta from attachment, video length?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- How to display *block number* instead *date value* on WordPress posts?
- Get_the_terms restrict output
- Conflict between wp_list_pages and get_posts – list pages not displaying
- Custom post type menu
- How to inherit field value from parent post into in child / sub post
- How to insert data into meta box from another plugin?
- How exclude or skip post type with get_next_post_link
- why post_class() function apply css classes to all other files?
- WordPress custom API endpoint – how to make the request more flexible
- Prevent A Specific Custom Post Type Showing In WP Search Results Page
- Create short URL with auto 301 redirect
- login_headertitle is deprecated since version 5.2.0
- YOAST SEO won’t work on custom post type archive [closed]
- providing access to post_id or post inside functions.php
- Removing full title and breadcrumb header container for a specific post type
- Is it possible to use array_walk() to append terms to an array of posts?
- WordPress notification if new post published
- Run shortcode in custom script in wp_head if post type is CPT ‘Jobs’
- Creating a non-hierarchical Taxonomy that behaves like categories
- Get current user id
- List All Custom Post Types Posts in Nav Menu Dynamically
- Only show columns in custom post type?
- Show current user posts in custom post type query
- How to Create a Separate Page for Blog Posts in WordPress
- Display custom post type for specific user
- Separate Content from gallery (custom post type)
- Custom Ratings for Theme, Proper way to Refactor Code and Clean up Template File
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- How to get the current category with custom posts
- Get post format
- Display Custom Post Types Glossary
- Custom Post type content within a slider
- posts within custom post type all share the same content in the front-end
- Shortcode to return single custom post based on post taxonomy
- How to export custom post type with ACF to individual file with automation?
- WordPress Count posts within a custom post type
- Custom post type in Custom widget – $listItem
- Add custom columns in custom post type browse page
- Displaying a custom post type using get_template_part into a specific layout
- Using Wp_Query, Json to add Highcharts series data
- Template code to split a post and print a custom field?
- Displaying a list of Contacts
- Different videos for different posts
- Custom Post Types and Removing Slugs – should we do it?
- Send post changes to set email addresses (not users or subscribers)
- Custom posts – tag pagination
- Create custom WP_List_Table in post_type
- Types plugin custom post add_action hooks
- Adding custom post formatting options in custom post types
- How should I structure complex content hierarchies?
- Twitter Product Cards
- WordPress as a frontend website for iOS app [closed]
- Function to limit number of custom post types on homepage – TwentyTen
- How can I make custom static widgets/areas on my homepage?
- Custom meta box in custom post type not working
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Convert Custom Table Data Based Plugin To Be Searchable
- Add Class according to the order of appearance
- Loading plugin text domain before registering post type
- Meta box not appearing in my custom post type
- New checkbox in custom widget isn’t saving data
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Let users upload image(s) to the post from front end
- Custom Content Type with No Page View
- Foreach loop returning more than one item when querying taxonomy
- Function to erase every post from a taxonomy
- How can I get some of a posts meta data whilst it is still inserting?
- add_action ‘init’ from inside a class for custom post types
- How to hide a custom field from admin?
- Have custom post type Visibility be private by default, and have radio button also set to “Private”
- Get terms for a specfic post from multiple taxonomies in custom post type
- Custom post type tags not showing in search
- Redirect to URL if x number of days passed
- Problems making shortcode with custom post types and taxonomy
- custom comment fields on CPT
- CMB select with data from CPT
- Add Class After 4th Post
- $wpdb is queried but results don’t show
- Display author box on just certain category posts?
- cannot achieve this structure (custom posts VS categories VS ??)
- How to list posts by term (custom taxonomy)
- Excerpt length: get first paragraph