If I understand correctly- this is an AJAX request, there is no $post var because you haven’t loaded anything from the database in this request. You have to pass both the ID you want to relate it to, and also the ID you want to relate it from, neither exist in the current request.
Related Posts:
- Storing posts from query and accessing later via AJAX call
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- JS innerhtml changing style when using AJAX
- Load Next Posts With AJAX not working with custom post type
- Load Next WordPress Posts With AJAX?
- WordPress notification if new post published
- Hide load more button if no more post in selected category
- Passing total post count to javascript
- Default post showing more than intended
- Ajax load more post button not showing
- Getting the URL of the parent page
- How to create custom boxes with text inside?
- How to add post_type=value when editing that post type in the WordPress admin?
- Adding dropdown select meta box to custom post type – seems restAPI is interfering
- Open Custom Post Type as PDF
- Using The REST API How To Pull All Custom Posts?
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- Ajax Check Post Status
- Insert post metadata for all posts in CPT at once if metadata no existent
- Show the same Article Available in Other Categories
- Getting posts under the custom post type ui category
- Received nothing after executing AJAX post function
- Filtering WP_Query Dynamically on the Front-End
- Why get_posts() not returning only selected category posts from Custom Post Type?
- If post has custom field then display css-class
- Loading custom content type from ajax results?
- Convert simple SQL Query to WordPress query
- Display only one post each WEEK
- Add meta value to custom post type on publish
- convert custom query to wp_query
- List children on child post
- Restrict custom post type from appearing with ?post_types=
- Show custom post type filtered by category
- create parent post using wp_insert_post
- Turn on and off custom post type from admin?
- Missing Posts in Custom Taxonomy List
- using $wpdb to get custom post type with term
- Display random posts, but omit the post it is on?
- How do I do this with WordPress? Taxonomies?
- Disable block with taxonomies at post page
- I would like to have different styles for my posts based on the content of each post
- Converting the_content string to an array?
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- Showing posts from different categories and from custom post type
- Get latest 3 posts from multiple CPT in one query
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Which post does a taxonomy term belongs to?
- List custom taxonomy specific to one custom post type
- Post image in WordPress not appearing on home page
- Meta query for custom post type ignored in main query
- Changing custom type name hides the posts
- Display Ad on Specific Categories
- AJAX load more for different custom post type loops
- Hiding posts by other users and non-logged in
- Display custom fields from custom posts in RSS feed
- Ajax Custom Post Filter is not filtering
- Update Post Meta for a logged in user
- Add custom field to Posts and sort by it
- Add custom post type settings to wordress default posts
- WP_Query inside foreach loop returning same value for all options when filtered using ajax
- Get related posts of child term of custom post type
- Two Custom Post Types Many to Many Relationship
- Problem with displaying posts in the CPT category
- Show titles, date of all posts on single category page
- Side effects of Script and Iframe in post
- How to change the post type a theme shows by default?
- Set a checkmark in a category based on a URL-parameter
- Several post types on WP Query by tag and taxonomy
- Custom post type – use ajax to display sub pages
- No Permission to add new Page, Post or CPT with Admin role
- Update postmeta Parent when post_status child change
- custom post type category count shortcode
- Portfolio Page for Classic Posts
- Add post location with mile radius allowing search
- Custom post type editor with dynamic selects, one drop down populating a second second drop down not working
- Get the category from custom post type
- Is it possible to store Custom Post Type data in separate set of tables and still have wp_post class functionality?
- Set up post page like JAMA articles
- Custom Post Slug same as Parents Category Slug
- Shortcode not working with post counter
- Changing default ‘posts’ parameters with register_post_type_args
- Admin Column does not populate with data
- Load Custom_post_type categories post with ajax
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Get terms that contain posts that in turn belong to other terms?
- Dynamic Custom Fields
- Prioritize posts in query by meta keys?
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Allow users to create posts without logging in?
- How to get all tags of a custom post type by id
- How to define which register_post_status goes to which register_post_type?
- Limit the post for differents custom post type in the same wp_query
- Pagination with custom query, custom search form, single and pages, ajax and no plugins
- 2 Different Custom Post Types in Submenu
- How to assign classes to all elements?
- How can I show 1 featured post in a styled element, and the next few below differently styled
- Some posts from custom post type to subdomains
- Save custom post type to external database
- How can i create an custom post template for an specific post category? [closed]
- Retrieve custom post types by custom taxonomies with WP_Query