$post
isn’t set in an admin-ajax.php request because you’re not querying for any post or inside a loop. In your script that sends the ajax request you’ll need to send the post ID and retrieve a post object in the callback:
function ajax_cart_send_mail(){
$post = get_post( $_POST['post_id'] );
$id = $post->ID;
$name = $post->post_title;
}
add_action('wp_ajax_ajax_cart_send_mail','ajax_cart_send_mail');
add_action('wp_ajax_nopriv_ajax_cart_send_mail','ajax_cart_send_mail');
Related Posts:
- greatest() function returns undefined property
- How to add specific script to WordPress webpage that will working with user input and databases
- Get Shortcode output to database for static post_content
- Is it bad practice to create own table for a plugin?
- How to export comments in WordPress?
- How can I call a function from one plugin within another plugin?
- Gutenberg disallow certain custom blocks but keep all core blocks?
- What are these entries in the database? Looks similar to JSON
- How to properly insert data into custom table via plugin
- Publish author posts only with editor approval?
- Replacing Icons in the Dashboard
- Customizing subject in comment notification e-mails
- WP showing “warning: call_user_func_array()”, What to do?
- Declare a function before plugin does on the theme functions.php file
- Generate Advanced Custom Fields box in custom admin menu page
- Removing user contact methods works from functions.php but not from a plugin
- Custom database table for plugin not creating on activation
- Use functionality of 2 wordpress plugins
- Should I global $wpdb outside of any of my plugin’s functions scope?
- How can i change an image’s author?
- Converting a simple plugin to be placed inside of functions.php
- Counting pageviews on high-traffic cached sites
- How to edit/delete single row items in a table on my own menu page
- Set WordPress Featured Image For All Post Slugs Matching Image File Name in Specified Directory
- Showing Co-Authors on post page
- jQuery Plugin to use WordPress functions in AJAX request
- Debugging Technique Question re: functions.php
- WP Job Manager Category Drop-down; Change Placeholder Text Via Filter
- Custom Taxonomy Tag Search
- Redeclare theme’s function in a plugin
- I have functions in my wordpress plugin. How do I get them to work for me?
- Change wordpress current_time function to different timezone
- How to override a plugin function wrapped in a class?
- Doubt using $wpbd->get_col for a single column
- Access WordPress database outside of WordPress
- Edit Yoast SEO breadcrumbs output [closed]
- WordPress Settings Lost After Site Migration
- Snippets: is it better to add them in functions.php or make site-specific plugins?
- Using a post-signup hook to get user details
- Restrict media upload size by format
- Show function to super admin
- Facebook Messager Plugin
- import posts with dutch/special letters
- Better ads plugin has 500.000 entries in wp_postmeta
- How to create multiple database tables on plugin activation?
- Does deleting a Plugin via the WordPress admin ‘completely’ remove the code?
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- Best/Correct way to add an option to a category
- Help with WP Business Directory Manager Plugin?
- Return multiple values in a shortcode attribute
- get specific value of a array | PHP
- Loading a plugin’s js file from functions.php
- Overriding an Array in a Plugin’s Class/Function from functions.php
- DB Query not working in Plugin
- Where do plugin variables live in the db?
- How to access OOP plugin function inside themes or other plugin
- Plugin: connect to external database without showing password
- Storing Form data in a different database
- Different registration form for different roles
- More than one WordPress site using the same database – how to disable plugin for one site?
- Elementor Pro display featured image on section -> style -> image using shortcode
- Dynamic URL Rewrite for Custom
- Create a pdf from the entries in DB
- RSS feeds for specific topics
- add_rewrite_rule to load different page, without changing URL in browser
- What database state changes happen after a post is manually “updated” with no changes?
- Can i stream data to a custom_post_type?
- How do I add a medium to the WordPress database with my own plugin?
- Overriding a function in a WordPress plugin
- Adding discount functionality to the cart
- Precheck fields when I add a new post
- Use buddypress function outside of plugin
- My wp database has been hacked
- How to update a database entry with a wordpress plugin?
- WPML – Hook when language is switched (change user language)
- Use action, filter, or hook to append HTML to WordPress plugin function
- Change custom rewrite rule when permalink is updated/changed
- How can I store user preferences in WordPress and retreive them later?
- Save Post Permalink In .txt File
- How To Add Code To WP Without Plugin or Functions
- one admin for 2 wordpress websites
- Disqus comments count taking long to update
- plugin not hooking to my custom hook
- Populate select option with JSON file
- Home page letters
- Find all strings between an enclosing shortcode
- Need help for creating custom table on wordpress
- Insert data in custom table during new post creation
- Trying to output a “Most visited blogs” list in wordpress multisite
- How to submit the custom form data in database in WordPress without plugin?
- Duplicator live to wamp https to http
- wordpress Search function is not working
- Is it possible to recover Deleted users?
- Adding a script & php to functions.php
- PHP Creating a formula from mysql db values and db stored math operator
- How to Add Extra Text In WordPress Title Before Post Publish
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- WordPress Convert queries to slashes using function.php
- plugin doesn’t retrieve data from database