This is not recommended, but if you want to do it, do it this way:
Save your file in your WordPress’s root folder, right next to index.php
. Then, require WordPress’s core files in it, by this code:
define('WP_USE_THEMES', false);
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require('wp-load.php');
Now, even though the file is not actually a part of WordPress, it can be treated as one, and you can do anything you want with it.
However this might cause security issues, so i recommend you only try it for educational purposes.
To communicate with WordPress using AJAX, use Rest-API instead. You can find an easy solution in this answer.
Related Posts:
- Apply class to every paragraph that holds image?
- Is there a way to parse shortcodes in PHP?
- is_admin returning false in backend in server side rendered block
- How to target with css, admin elements according to user role level?
- remove tags from posts in php
- Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
- Getting key value of WP_Term object in wordpress
- How do I create a drop down menu in a widget?
- Showing user ID on user main page from screen options
- Delete post revisions on post publish
- Alter secondary loop to exclude posts from current page category
- how to add display_name from the users table to this query
- How to override .htaccess with new rules without ftp or edit it manual
- Adding graphics to 404.php page
- Why when I instantiate wp_error in a validation method my user registration method stops working?
- How do I list the_tags() into HTML data-attribute
- WP Insert Post function – Insert Post Thumbnail
- get_usermeta() deprecated in favor of get_user_meta(). But why doesn’t it make use of it?
- Convert a date to ISO8601 date format
- Check if term object is in array
- Highlight Current Tag in wp_tag_cloud
- Getting rid of role=”navigation” in the Home Page Pagination
- How to prevent those PHP variables from being cached on WordPress?
- Use ajax from function.php
- Single.php back button to parent category
- How can I hide Home in my menu in a specific page?
- Same log message keeps on printing to debug.log file thousand of times
- Trigger popup in a php if/else statement
- Anyway to output the registration form like the login form with wp_login_form()?
- Setting a cookie upon specific URL visit
- WordPress custom slug (endpoint) and compare all links
- Only show search results with if current date is between two dates?
- Remove duplicates – array_unique()
- wp_query with cat not working
- Compare post-IDs within WP_Query? (Less than / Greater than)
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Capture User Email Address When Filling Out Form
- WordPress returning 404 for multisite pages
- How to debug my custom login form looping intermittently
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- Execute long and heavy processes
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- WordPress displaying content from sub pages
- jQuery code not working when included in functions.php
- Widgets in the loop if active
- Fatal Errors on pluggable.php
- Blob file download problem
- Fatal error: Call to undefined function register_new_user()
- Remove the More Link
- How to display SQL query that ran in WC_Order_Query?
- Post not populating for custom post type based on category selection
- How to display success message correctly and delete it when the page is refreshed
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- How to display meta_value array?
- ‘Bones’ theme: Load stock scripts in footer instead of header?
- Wrap posts p tags in div
- Adding Separator to Breadcrumbs
- Display Custom Field in Sidebar if Value is Present
- Update user repeater meta (ACF) with another user meta field value
- How to set post to draft and not publish if the_content contains certain words?
- Want to unrestrict plugin block
- Highlighting Text in Search Results
- is it possible for a URL to filter by tag
- Add Featured Image to Existing Post
- How to get latest post ID in functions.php?
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- Preserving backslashes in post_content
- How to make a pagination with dropdown selection?
- update_post_meta not working, but values are true
- Woocommerce – get daily sales meta
- update_user_meta not working
- Change CSS Variable value in Theme Customizer Live Preview
- Importing the style and scripts in the plugin doesn’t work as well as in the theme
- gettint error 400 with AJAX
- Show different number of posts on first Blog listing page
- Change username link in admin bar
- Update all posts in custom post types with wp_cron()?
- Child theme not visible in backend
- Custom theme: adding unwanted tags in the content
- how to check if the post id has a new comment?
- How to change this internal image link parameter using PHP?
- php if, else & custom fields – syntax error
- How to show all of aspecific post type that has taxonomy and a specific term
- Why isn’t my custom function kicking in from my functions.php file?
- Banner editable from backend
- Shortcoding with Divs
- Adding else if conditional statement to purchased theme
- Reusing the page name class that WordPress adds to body tag
- How to include support for all page types, calendar urls, archive, etc
- archive per year with monthly
- How do I remove blog entries from home page Twenty Eleven child theme?
- PHP 7.3 is required for WordPress 5.2 or Recommendation
- Add multiple HTML attributes to an Elementor button
- Customize the summary table of an order in the email
- How to sort custom sortable column by custom table value
- How to disable page create for custom post type, but allow a page with the post types slug to be created?
- WooCommerce Modal Fly cart on add to cart – With AJAX
- /page/2/ redirect to 404