To get data from AJAX call you have to echo
or print
it. In WordPress you should use wp_send_json()
function to send data as response to call.
function mh_get_addons( $args = array() ) {
$defaults = array(
'posts_per_page' => -1,
'orderby' => 'post_title',
'order' => 'DESC',
'post_type' => 'mh-addon',
'post_status' => 'publish'
);
$args = wp_parse_args( $args, $defaults );
$addons = get_posts( $args );
wp_send_json( apply_filters( 'mh_get_addons', $addons ) );
} // mh_get_addons
Related Posts:
- WordPress ajax get content post id
- Loading post template that contains a nested loop with ajax
- AJAX – get_posts for a specific post type returns empty
- Portfolio list view after clicking back button
- How to get data with Select AJAX PHP
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- Ajax in a settings page (update_option is undefined)
- Ajax and autocomplete
- admin-ajax.php vs Custom Page Template for Ajax Requests
- Saving (Updating) Post / Page Edits With AJAX
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- How to correctly load wordpress in a non WP script for AJAX request
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- CPU usage: AJAX and Heartbeat API on admin pages
- Confused on AJAX submit form through page template
- Ajax call in wordpress not working for subscriber user in front site
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- WP_Session not acting with AJAX
- Ajaxing in functions.php
- add_action and Ajax
- Embedded Twitter feed won’t render nicely when loaded via Ajax
- Enqueue script dinamically
- Most performant way of fetching remote API data?
- Admin-ajax responds with 0 due to empty $_REQUEST
- Enqueue script in header
- Using ajax with wordpress
- Using foreach inside an ajax function
- WP_User_Query ignoring ‘meta_query’ arguments
- Ajax Modal Flickers When Opened Multiple Times
- Ajax image upload with media_handle_upload and form.js
- Edit a different page in WP Customizer
- Get the_content with ajax
- Caching-Plugins and Ajax-Page-Parts
- Ajax loading duplicate post
- WordPress AJAX – how to return true or false in the callback function
- Admin ajax error 400 when passing select value to populate another select
- WordPress Ajax POST Error 403 admin-ajax.php
- How do I detect in which page ajax_query_attachments_args is loaded?
- Ajax post returning full html page as response
- Which allowed API hooks work to add wp_ajax action?
- Pass additional parameter with async upload
- AJAX request randomly stop working and returns error 400
- Sending variable from ajax on form submit
- Ajax store response json in variables
- Performance optimization of tree like structure
- WordPress search results with Ajax, get_post_type() not working
- How can I set cookies on both secure and non-secure origins at the same time?
- Variable Products Being Added to Cart with AJAX on Shop and Category Pages
- Is it secure to use admin-ajax.php in front?
- Best way to use ajax front-end?
- ajax is returning 0
- merge wp rest api query to get posts per category does not work
- use jQuery.load() to include a php file in a div, wp_query() is part of php file
- WP AJAX post filter > do something with empty value
- How to make a fetch() POST request to wordpress rest api?
- Load more posts in the same category – Ajax + Timber
- How to jQuery Ajax show new data from successful insert?
- Something strange with ajax
- admin-ajax.php returns 0 even when the post status code is 200 OK
- is there’s a way to get the next page content generated by page break block with ajax call?
- Merge PDF files from post custom fields(ACF) into one PDF file and respond back the created PDF file, WordPress(AJAX Request)
- How to get next and previous post into ajax formed modal windows?
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Is there a public ajax endpoint?
- Why Ajax Doesn’t Work?
- How can i do public ajax call?
- How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)
- wp_verify_nonce not working on the mobile device
- Frontend AJAX Media Upload returning 404
- Can’t GET Variable from AJAX URL
- JS global variable doesn’t update
- How to update cart total after AJAX success
- How to implement AJAX within a class storing shortcode atts as class variables
- Jquery wrap permalink in a data-attribute?
- How do I display posts of a specific day?
- (Frontend AJAX) get post data WITH image thumbnail?
- Load .php file into div using ajax
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Ajax Function call is always returning 0 in front end(without plugin) [closed]
- AJAX Post from same domain to a wordpress page
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Using AJAX for dynamic settings pages
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- wp_localize_script not create variable in head section
- Add “load more” functionality to an AJAX response
- weird Internal Server Error – no error log produced
- Why are the most recent posts not appearing in a fetch request, unless I’m logged in?
- Successful ajax call returns lots of whitespace and text of code with 0
- How to submit a button automatically after every scheduled hours?
- At what stage does wp_ajax hooks gets applied during WordPress request?