如何使用AJAX调用Wordpress函数?

I'm a newbie to Wordpress and PHP and I'm trying to load more posts on a button click (i tried infinite scroll, but it isn't exactly what I'm looking for). I echoed the admin-ajax URL into my HTML and I'm getting it from an input and sending along some data via Jquery Post function. The request is fine, i get no errors, but it just returns 0 and i don't know if it's reaching my desired function.

So, how can i:

  • Be sure it is reaching my function?
  • How to return some html data from my function?

Here's my JS code:

$('.loadMore-button-link').click(function() {
    var me = $(this);
    var adminUrl = $('#inputAdminAjax').val();

    var data = {
        posts_per_page: 3,
        post_offset: postOffset,
        action: 'getPosts'
    };
    $.post(adminUrl, data, function(response) {
        alert(response);
    });

    return false;
});

Here's my PHP code (in my functions.php file):

add_action("wp_ajax_getPosts", "getPosts");
add_action("wp_ajax_nopriv_getPosts", "getPosts");

function getPosts() {
    global $wpdb;

    var postOffset = $_POST['postOffset'];

    query_posts(array(
        'category_name' => 'portfolio',
        'posts_per_page' => $_POST['posts_per_page'])
    );

    return 1; //this was a test
}

Thanks in advance.