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
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- How can I display a Divi content inside a modal based on an AJAX request
- Custom location for attached images
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- WooCommerce – Reset quantity input field when variation changes
- Query all posts of a custom taxonomy term
- get current product name in functions.php
- class click counter save number
- Get first URL from post content
- Setting custom canonical urls
- Handling Body class based on Template
- Trigger popup in a php if/else statement
- Setting a cookie upon specific URL visit
- Any possible way to make $wpdb->get_results() return anything else than array?
- Get_avatar filter?
- Can’t get page content in WordPress
- WordPress child theme fails to override parent navigation menu in /inc/structure/header.php
- Way to querry data (tags) from a wordpress database?
- Why is $_REQUEST an empty array in admin-ajax.php?
- Adding Default Settings to Theme My Login plugin
- Image as Sales Badge
- Checking for new message using AJAX and PHP. Server overload?
- how to make separate field in wordpress user_data_
- Function not working at one place
- jQuery not defined
- Displaying the Month and Year that a page was Created?
- Changing custom logo link
- AJAX request status 200 but no actual “response”
- get current custom post ID by WP_Query method
- WooCommerce – Email admin with new user details
- Add a class to the anchor tag on HTML5 gallery
- Conditional Header in wordpress
- How to make drop down post title
- Ajax not working es expected (Returns 0)
- Remove meta description on certain pages
- Menu — How to add “current-menu-grand-ancestor” css class
- Create onClick Event to Re-load a Widget
- Use menu link or onClick to set a variable
- Swapping wp_dropdown_categories function with wp_category_checklist
- functions.php is being included twice, creating PHP fatal errors
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Automatically remove a canceled order in Woocommerce
- Display fields as values in array from external SQL DB
- Only Show Link If div Exists
- How to put a variable in a instance in the widget