I had a similar problem, global $post; was returning NULL. But it works fine if I don’t use short codes.
So I found a function for getting the post id from the URI, you might be able to extend it to get more information if you need it.
Try this:
var_dump(url_to_postid($_SERVER['REQUEST_URI']));
Related Posts:
- Where to put my code: plugin or functions.php?
- Create a shortcode to display custom post types with a specific taxonomy
- Add Content to Page without shortcodes
- How can I fix those issues generated by the Themecheck plugin
- Shortcode Displaying Custom Post Types
- Using shortcodes to parse POST request (containing the data from a front-end form)
- Custom Select Query with Custom Post Types
- IF statement in a do_shortcode
- Strip shortcode from specific post types (formats)
- Pagination in a Shortcode. Get_next_posts_link not working but get_previous_posts_link works fine right next to it
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- How would I create a shortcode to display a custom post within a page or regular post?
- Is it possible to create a shortcode that will query a post based on taxonomies?
- Get custom posts with certain ids in a custom loop using a shortcode
- Custom Post Type Loop within Shortcode
- Shortcode doesn’t display in custom post type
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- How to create shortcode to display custom field value on a custom post type
- How to enable shortcodes in a custom post type?
- Get custom fields from a custom post type with a shortcode
- Get custom post type list for every category shortcode
- How to render a custom post type template with custom fields using shortcode
- Form action/link to render a plugin in WordPress front-end
- custom post type category count shortcode
- Display Child Pages of Custom Post Type Parent Page
- Shortcode to display Staff post type based on Location post type and Specialty post type
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- Shortcode for CPT post content in a page
- Next Post links not working in custom post type shortcode
- Foreach inside shortcode not working as planned
- How to retrieve category of a post in have_post loop?
- Checking if looped item has a parent inside a shortcode
- the_post() is printing titles in page footer
- Add custom attributes to a post
- Custom shortcode works in Elementor editor but not on frontend
- Get Posts by Category, Tag , and CPT Taxonomy
- post_type internal ID?
- Custom post type Shortcodes wordpress
- how to create custom post type with dynamic category_name using shortcode
- Add shortcode inside of the_content()
- WordPress Custom Post Type and Shortcode for Portfolio Items
- Creating shortcode id for custom post types
- Filter content in shortcode
- Shortcode with WP_Query more than once on one page
- Custom Post Type for Shortcode Use – Prevent it display as a post (with slug)
- How to call a post’s metadata in shortcode.php?
- Trying to write shortcode with get_post_meta but isn’t working
- Shortcode / WP_Query in post changes context
- How to display class name in this shortcode post query
- Modify a plugin function output from another plugin
- Problems making shortcode with custom post types and taxonomy
- Using Custom Post Meta Values in Shortcode
- Why is my custom post query shortcode only showing 1 post?
- Content in WP Editor displayed below CPT shortcode [duplicate]
- How do I output a list of a specific post type in a table?
- How to make post templates to include shortcodes only?
- How to show Custom Post Type – Case Study using Shortcode & ACF
- Alike Shortcode using in Custom Shortcode
- Show in an entry a Custom Post Type associated to a post
- Create a CPT to edit Shortcodes Atts
- Display CPT Category List as Shortcode
- Can Someone help me to create Short Code for displaying a category posts
- Shortcode with loop stacks output
- background featured image display using shortcode
- How to display the post using a shortcode in WordPress?
- WordPress shortcode to pull product post data
- How to generate auto shortcode for custom post type same as Elementor Template?
- Why can’t I filter my CPT shortcode by category?
- From CPT Custom Loop into Shortcode?
- editing shortcode for custom post type within a plugin
- Button link display in shortcodes using custom field in ACF
- Custom post type shortcode with taxonomy attribute not working and no errors
- Shortcode and get_template_part
- WordPress post not executing shortcode until updated
- Display Custom Post Type Archive content with Shortcode
- Load custom post type with ID in a shortcode
- Extracting Post ID and passing through as an attribute in a shortcode
- Enable shortcodes on custom post type
- Custom meta box in editor of custom post type not working
- Plugin Error on activating
- Ads below footer
- Shortcode error
- Modify shortcode to work with custom taxonomies and slugs
- Custom Info Box at end of posts?
- Shortcodes in custom post fields without the_content()
- Shortcode display CPT Query only showing 1 post?
- Using get_terms() as shortcode attribute
- adding a shortcode into a custom post type
- Nested loop called with shortcode duplicating the content above the main loop
- Add number in increment of one to DIV ID
- shortcode for recent custom type post
- Navigation links to posts in current term shortcode
- Rewrite a filter as shortcode (or something like that) to use anywhere in CPT
- Display posts from another page on home page in wp-editor
- How to loop through a custom post type using a shortcode and output each element in the loop using shortcodes
- Display page and custom post title inside shortcode
- trying to display custom post type with custom taxonomy value by shortcode can’t works [closed]
- How to separate posts by categories?
- Problem with shortcode
- select categories by ids/display terms only selected