You’re firing a request to a PHP file that won’t have the WordPress library loaded – hence the undefined function error.
You could manually load in WordPress with something like require '../../../wp-load.php'
.
Or, better yet, use the awesome AJAX API. Just fire your request to wp-admin/admin-ajax.php
and then register a callback in your plugin or theme that matches the action
parameter (in your case, load_blog_posts_sidebar
):
function wpse_147692_load_blog_posts_sidebar() {
// Do something!
exit;
}
add_action( 'wp_ajax_nopriv_load_blog_posts_sidebar', 'wpse_147692_load_blog_posts_sidebar' );
add_action( 'wp_ajax_load_blog_posts_sidebar', 'wpse_147692_load_blog_posts_sidebar' );