So, if you want it to fire on the front-end for both visitors users and logged-in users, you can do this:
add_action( 'wp_ajax_my_action', 'my_action_callback' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' );
Example
add_action( 'wp_ajax_GetPostMedia', 'GetPostMedia' );
add_action( 'wp_ajax_nopriv_GetPostMedia', 'GetPostMedia' );
Related Posts:
- username_exists() function can’t be access without logging in
- How do I remove a require_once admin panel from the parent theme from the child theme functions.php?
- Can i check if user is doing any ajax request?
- How to add default images into theme customizer image control?
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Validate a users email address when using gmail to register
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- Why is this Ajax not working?
- get post based on category chosen in drop down – The ajax method
- How to store data from multiple forms using ajax and php
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- dynamic dependent select dropdown
- how to make custom ajax handler?
- How to disable controls in theme customizer?
- is_user_logged_in() not working in AJAX validation call
- Using data sent via AJAX in multiple functions on a WP plugin
- Function won’t run onclick using Ajax
- Simple AJAX notification when the new post is added to the database
- Why i can’t get custom fields value or post ID via Ajax?
- Post not populating for custom post type based on category selection
- How to get post category list as select in front-end?
- Is there a hack for using is_page() within the function.php file?
- Execute Jquery when a specific page in my plugin is loading
- Adding a ‘style=’ bit to image_send_to_editor output
- AJAX function not working [closed]
- Disclaimer that will show every refresh of the page
- Database entry removed on browser refresh, Ajax PHP jQuery
- Store ajax data in PHP variable
- Multiple AJAX handler functions conflict in functions.php
- Ajax filter with loadmore button
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- register_block_type is not working properly
- get_the_author_meta( ‘ID’ ) just return 1
- Update $wpdb query with AJAX
- Can an AJAX callback function access a PHP variable which was defined during initial page load?
- WordPress Ajax filter: Create two loops for different output styles?
- Access to “My Site” is missing from the admin bar
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Offset with ajax load more posts duplicates
- ajaxurl usage for a custom function
- How to call a function from functions.php with ajax?
- Custom Post type Ajax search results
- Find the method which AJAX GET calls
- AJAX Returning Way Too Many Posts
- wp_delete_comment is doing nothing
- Modify category archive page loop on functions.php
- Registration form not registering First and Last name
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- AJAX WP_Query’s order and orderby parameters not working
- Mega Menu Walker
- Autoloading in Child Theme
- How to add a class to the attachment images
- Looking for a better way to handle an ajax script that pulls in post data on click
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Passing jQuery value using Ajax to a page template
- Change logo based on incoming domain
- How to make drop down post title
- Remove meta description on certain pages
- Image media upload metabox
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- WordPress, AJAX and pre_get_posts using conditional tags
- Limit 1 global comment per minute
- Is there a way to conditionally check whether a WordPress post title is empty?
- Echo a function inside a function
- Use WordPress function in php file
- wp_force_remove_style’ not found
- how to save checkbox data for custom setting?
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Enqueing External JS on the remote server JS
- My jQuery Ajax form submit is still refreshing page?
- Get the name of menu item with wp_nav_menu
- I installed WordPress locally now how do I login?
- Remove submenu item from list
- Customize field names in backend profile edit page through function.php [duplicate]
- Time Delay a URL Redirect for Specific Page
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- Run a sql (update) after 12 hours after the user login. Woocommerce users
- Wp_Schedule_Event every few minutes doesn’t work
- File from parent theme imported to child theme doesn’t work – any ideas?
- AJAX numerical pagination problem in TwentyFifteen-child theme
- How to center all text body in single.php at once?
- Access WP files on “server 1”, from “server 2” – using wp-load on an external website
- Popular Post Not Show
- WordPress styling recent post
- syntax error unexpected ‘}’ at 364 line
- get_post_meta no longer working
- Highlight posts currently being edited on multiple editor site?
- Assign new post author IF another user in custom field on post transition
- Create and publish a new post every Monday, listing the post titles and links to the posts published during the previous week
- How do I change the Go To Categories link in the term_updated_messages
- Remove Woocommerce product from cart with ajax/fetch
- How to pass value to add_filter wpcf7_form_tag from another function?