$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
- Best collection of code for your 'functions.php' file [closed]
- Between functions.php (theme), widgets, and plugins, which is loaded first?
- Where do I put the code snippets I found here or somewhere else on the web?
- Manually set global $post vars with an ID, in order to use template tags
- Disable plugin / plugin action via theme
- How do I show data from gravity forms in my template? [closed]
- Delete tables from database when deleting plugin
- Is it bad practice to create own table for a plugin?
- How do I call wp_get_current_user() in a plugin when plugins are loaded before pluggable.php?
- How to Add an Index to Plugin Database table
- How do I replace a function, declared inside a plugin’s class, in functions.php?
- How can I delete orphan keys in WordPress database tables?
- Is there a plugin that will override the “Error establishing a database connection” message? [closed]
- How to not allow users to create new tags, but allow to them to use existing ones
- How to export comments in WordPress?
- How to include a plugin’s php file to another plugin functions file [duplicate]
- How to delete all records from or empty a custom database table?
- How can I call a function from one plugin within another plugin?
- Shared functionality in plugins and themes
- Gutenberg disallow certain custom blocks but keep all core blocks?
- What are these entries in the database? Looks similar to JSON
- WordPress sharding: which multi-DB plugin to use?
- Remote upload file to server B
- Creating two database tables via plugin
- How to properly insert data into custom table via plugin
- Publish author posts only with editor approval?
- Replacing Icons in the Dashboard
- How to remove WPML Generator Meta Tag by theme’s functions.php (override plugin function)? [closed]
- How does WordPress handle MySQL row lock errors?
- How to make sense of the active_plugins option_value to enable and disable certain plugins from the database?
- Plugin update error message
- Limit access to posts/pages by user roles
- Using functions from a plugin in your theme
- Prevent publishing the post before setting a featured image?
- Keep one user logged for a year?
- Remove Google Fonts Which Are (Probably) Added By Plugins
- Customizing subject in comment notification e-mails
- if plugin is active? check if plugin is enabled or not?
- How to empty wordpress custom post Database table
- insert data in database table from plugin with WP3.1
- Simple form that saves to database
- Common functionality between my own plugins
- WP showing “warning: call_user_func_array()”, What to do?
- How to run Two WordPress blogs with different themes and with single database and same content
- Need to create a Theme demo site that features multiple themes
- Adding a text domain to every __(), _e() and __n() gettext call without a plan to create own translations
- $wpdb->get_results leaking memory
- Define Function in functions.php or plugin and call in theme loop
- Autogenerate wordpress shortcodes using array?
- Plugins or Tutorials for displaying data from SQL-db on WP-page? [closed]
- How to Loop Plugin Option Field Set?
- Insert query inserts 2 entries, should insert 1
- Using Vagrant for customizable WordPress Multi-sites [closed]
- Can we completely remove the WordPress Sitemaps (WordPress 5.5)?
- Is it a bad practice to go directly to the mysql database while developing a plugin?
- Updating WordPress – the best approach (updating wp core, plugins and db)
- Declare a function before plugin does on the theme functions.php file
- How do I check what plugins are enabled via the database?
- How to handel multiple checkbox field in the admin settings page with Settings API
- Why does including a file in theme’s functions.php not work?
- wp_insert_user – how to send verification email before logging in
- How to override a theme function (within a class) using a plugin
- Editor access to plugin settings
- WooCommerce create new product and add to cart on form submit
- Seeking clarification on page request life-cycle
- How to store ACF custom fields data in a custom table
- Can I explicitly specify ENGINE=InnoDB in WordPress?
- Generate Advanced Custom Fields box in custom admin menu page
- How to assign user a role if none is present when logging in
- How can a Firebase user registration and login be integrated into a WordPress site?
- Is the WordPress HTTPS Plugin Still Safe To Use? [closed]
- Saving Plugin settings to the database
- Bad Request (Invalid Hostname) on working server, database problem
- Set a User as Author of all ‘New Posts’ posted
- Plugin Not Working, But Only On GoDaddy Hosted site
- Create custom column in post table in wordpress
- Custom database or Custom Post Types?
- Shortcode display outside the div
- Post source link plugin – small modification
- Adding New Role
- Change destination author link
- How to turn off email you receive when registered?
- Removing user contact methods works from functions.php but not from a plugin
- Execute a function using ajax
- Shortcode under a Shortcode Multiple times Possible?
- Custom Widget outputs the input but doesn’t save anything inside the textarea
- Custom database table for plugin not creating on activation
- WordPress plugin DB upgrade
- How do you auto-activate plugins from child themes
- How to update widget_text in the wp_options table
- How to call a plugin function in footer.php
- Add Top-Level Menu that opens URL
- How to load plugin before the wordpress jquery?
- How to remove action from plugin?
- While Using Static Pages, How Can I Get /blog into the URL of Each Post?
- Get the last post ID
- Add agenda items and notifications