then i found one way , that is create new template page which called json.php for example . it echoing the data in json formating .
No. You should never make direct requests to php files inside a theme or plugin, and you don’t need to create page templates to handle AJAX requests.
If you need to handle a form, make the request to the same page that served the form and inspect the POST/GET variables.
If you need to make an AJAX request using javascript, do it to the REST API. You can register an endpoint URL with a pretty url that will respond with JSON that can be easily processed in javascript.
When registering the endpoint, you tell it the name you want for the URL, e.g. /wp-json/hossein/v1/searchdatabase
, and you tell it a function to call when it’s used. That function is where you do the searching of your database, and you return the data you want to send to the browser.
Related Posts:
- Changing the entire control choices using wp.customize with JavaScript
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- How bad is it if I write AJAX functions using wp-load.php?
- redirect does not work in ajax function
- Add a preview to a WordPress Control Panel
- WordPress Customizer Typography: How to load just the unique Google Fonts?
- Can’t access WordPress functions in file called via Ajax?
- How WordPress converts URL to $query_string
- How to Globally Use wp_localize_script() Ajax URL
- trying to use wp_handle_upload with ajax
- Using AJAX in wordpress theme
- Using an if statement in the theme customizer page
- Retrieve localised value
- AJAXIFY WordPress Theme Frontend menu
- Post thumbnail to append post content via ajax click event
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- ajax response -1 in wordpress theme
- Why does admin-ajax load slow and what are ways to speed it up?
- Why WordPress AJAX returns undefined however it works fine when I add static url instead of dynamic function?
- How to use ajax in wordpress and sending the data without refreshing ?
- Issue on Accessing To Ajax Enqeued File to Pass to URL for Ajax Call
- pass wordpress template directory into ajax url call
- Ajax call returns 0 when add_action is inside a class in functions.php
- Retrieve WordPress’ the_content() with jQuery
- AJAX call fails when sending JSON but works with URL style string
- Pagination don’t work with active filters
- Woocommerce AJAX filters option loading spiner – problem on mobile device
- How to properly use AWS SES for a contact form?
- WordPress Insert ads after every 5th post
- Why excerpt hook not working inside ajax function?
- Theme functions don’t work as expected in partial included via get_template_part() after custom query using Ajax [duplicate]
- How to load jQuery with Ajax in WP version 5.3.2?
- Ajax Comment Upvotes – Votes don’t always register
- use a single nonce in three different nonce field
- Infinite scroll without plugin using ajax
- my ajax wont sent the data, please correct my code
- wp_kses allow checkbox class and checked
- WordPress Ajax Spitting out a page as a response?
- Using Customizer value in an external PHP file inside a theme
- How to avoid Ajax in wordpress theme in making mulitple request?
- Allow access to stand-alone php file WordPress
- Which function(s) to build a paged HTML table
- Using Ajax and WP_Query to load more posts on category page fails
- Can I use application/json content type in WordPress
- In wordpress customizer div still showing even if I hid it with javascript
- How to render block editor in wp-admin custom pages programmatically
- Host Private Custom Theme
- Theme author.php transfer
- How to add custom theme in hosting server?
- how to create/register menu items that can be added to menus later
- Is there a plugin for versioning files in the theme (style , .js and .php files)?
- Why not works the search.php file?
- restrain filter on get_the_excerpt to queried item in stead of current post
- Theme has disappeared
- My wordpress theme name isn’t updating straight away
- Post Featured Image Custom Sizing?
- Calling a WP Plugin Function’s Variable in Theme Template [duplicate]
- get_avatar() is not working in my custom theme
- wanted to sort the wp_query array by two ACF field (Year and month)
- how to unlocalize theme/plugin?
- GET request return value as error instead of success
- WordPress theme header.php should I add title meta?
- Social-Link block not loading html on page with custom theme
- How to diagnose wp-env environment problem
- Why nav_menu_css_class doesn’t work with apply_filters?
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- how can i remove js file from my footer in wordpress
- WordPress Admin bar missing from custom theme
- Custom Enfold theme tab layout not compatible with WPML
- Attribute form NumberControl doesn’t update when I update page before it lose its focus
- Best way to give user the option to make a menu, mega menu?
- How do I open a post in a custom page in wordpress?
- How to make force_balance_tags balance comment tag
- How to enable admin to upload multiple images to support header carousel slider theme in WordPress?
- A Reviews Page is Showing root Index.php instead of Template-Page
- Ensure SQL changes carry over
- Twentytwenty theme p-tags break em- and strong-tags that span several paragraphs
- How do I change the color of individual page titles in WordPress?
- Strict Folder and File Permissions for WordPress Themes Folder
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- Add class every 4 post like , class_1, class_2, class_3, class_4 and class_1, class_2, class_3, class_4
- Using wp_send_json_success instead of $result[‘message’], die, etc
- In a plugin, How to update a json file using ajax
- Programatically Created Menu not Editable in Dashboard
- No templates for condition page.php Elementor
- Using has_term() function for category-subcategory structure
- Does single webpage do not need navigation to create a slug in permalink?
- How do I make my terms for each product display via foreach loop? (woocommerce)
- Posts Page shows Classic Editor interface not Gutenberg
- White screen of death on index.php page 3 and above?
- Comment Form Development Issue
- Getting post URL within custom content template
- Best way to declare product variables in woocommerce theme development?
- Adding a button to wp/aution plugin
- Why front-page.php doesn’t show content of file instead shows loop
- Removing element from DOM with jquery through plugin Custom Scripts for Customizer
- How to Detect “Your homepage displays” setting in wordpress
- Why does wp_customizer default values do not apply when theme is installed for the first time?
- WordPress and Semantic UI
- hide theme files for admin beneath root