It’s failing because WordPress isn’t loaded. Instead of making AJAX requests directly to PHP files in your theme, make them to a REST API endpoint.
For example:
add_action( 'rest_api_init', function () {
register_rest_route( 'petebolduc/v1', '/test/', array(
'callback' => 'petebolduc_ajax'
) );
} );
function petebolduc( $parameters ) {
$foo = $parameters['foo'];
return "foo is " . $foo;
}
With that code, visiting: example.com/wp-json/petebolduc/v1/test?foo=bar
gives:
"foo is bar"
Related Posts:
- List users by last name in WP_User_Query
- Wp_User_Query not sorting by meta key
- WP_User_Query with combined meta query – not working?
- pre_user_query meta_query admin user list
- How to use search_columns in WP_User_Query?
- How to query users who have empty first_name?
- WordPress User getting added with id of 0
- WP User Query fails when searching meta queries and search columns
- Getting users by specific capability, not role
- how to know when the user is in specific part of the website and when he leaves that part and display the data in the admin dashboard
- WP_User_Query – searching multiple fields
- Accessing current users data within a plugin
- How to activate the user search
- List Users alphabetically with heading
- How to get the count
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Display the line breaks in user bio without using html
- User with same Mail but a different additional info(like domain)
- SQL to set Display Name to First Name + Last Name
- Cannot update newly added User field using wp_update_user
- Getting user data via ajax
- Find count of WordPress users by role and search string for user name
- Sort users by custom user meta value
- Show only users with the same role in Dashboard user list
- Remove Ability for Other Users to View Administrator in User List?
- Automatically delete inactive users after 2 months
- Allowing users to edit only their page and nobody else’s
- how to use joomla password format in wordpress?
- How to do get_users() with multiple meta_keys
- Limiting the number of users
- Force display name as full name
- ‘username_exists’ still returns an ID even after deleting record from the database?
- Track logged in users’ visits
- order users with drag’n’drop?
- Force users to complete their profile after they register? How to
- include user profiles in search results?
- Plugin that would allow WordPress Authors to “follow” other Authors and query “Activity Info” from that
- How to delete users with no order history through phpmyadmin sql?
- User profile custom field
- Authors Page : A page of authors
- How-to Delay The Capability To Publish Posts?
- Multiple Single Installs of WordPress with a central user base
- Limit content by user registration date
- What is the best way to avoid spammers registering to my blog?
- Authenticate user using Hashed Password in MySQL Query and C#
- What do spammers gain by signing up as a user?
- add ‘file upload’ field to user details
- Completely hide user info
- Gravity Forms Submit form as another user
- get_userdata by username
- Prevent Admin user to edit/see super admin from users list
- How can I check if the admin bar is visible to the current user?
- Redirect User to Homepage if no other redirect is specified
- Set default page for user account in admin
- Searchable meta value in user.php
- How wordpress retrieves user info?
- Find out who created a certain user?
- Locate authors on Google map version 3
- trying to list users & display first – last name
- Get users order by meta key with limit
- Hide everything on site for visitors except specific page IDs
- current user can edit user?
- WordPress Authentication Middleware
- the_author_meta(‘user_url’, $author->ID) not working properly. how can I solve this?
- Add email addresses to already registered users
- How to set show admin bar front to true for all users?
- Order users by last word of last name
- show text If special user is logged
- Multiple Backend Users as single Frontend User
- Forcing WordPress to work differently
- Does WordPress Importer notify imported Users?
- Remove user profile field [duplicate]
- Can user login details be used for other applications?
- Fatal error: Call to undefined function get_users()
- Allow user access to Dashboard only!
- Does an AJAX call on the Admin Side Automatically include the User Data/Capabilities?
- Bulk create clean user_nicename from user_email with SQL function
- Updating wp_user_level on user update
- WP_User_List -> How to open a new edit-page in WordPress admin backend!
- How can I attach a user to another user with user meta
- How do I protect user_activation_key?
- WP not logging in at first time
- Print profile details as PDF or from modal window
- How to check User Role and redirect to specific page according to Role when login in WordPress?
- Users – remove ‘send password’ checkbox
- Send email to all registered users [closed]
- Send clear password via mail
- How to get users by specific ID’s WordPress
- how to set default update_user_meta values wordpress
- Didn’t get array of users like in delete action WPList table in users tab
- Cannot Update user meta in custom field
- How to programmatically read the plan text password when user register?
- Get user id after save post
- I want to change my user name
- Unique password to access a section site
- Is there a way to rate users instead of posts?
- Ordering list of users by last name and then by first name
- Email Subscribe for Downloads in WordPress
- Cant edit profile from frontend
- User Query Multiple Orderby Clause