如何将wordpress过滤器应用于ajax加载的数据?

时间:2015-07-03 11:32:42

标签: ajax wordpress

我已经为内容创建了一个ajax函数和过滤器,但是当我使用ajax响应获取数据时,我的过滤器不起作用。请帮我。这是我的代码:

add_action("wp_ajax_nopriv_thb_infinite_ajax", "thb_infinite_ajax");
add_action("wp_ajax_thb_infinite_ajax", "thb_infinite_ajax");
function thb_infinite_ajax() {
   $args = array(
        'p' => $previous_post->ID,
        'no_found_rows' => true,
        'posts_per_page' => 1
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

        the_content();
    endwhile; else : endif;

}

add_filter ( 'the_content', 'wpsabox_author_box', 5 );

wpsabox_author_box($content) {
    return $content.'----';
}

JS代码:

                       $.ajax( ajaxurl, {
                                method : 'POST',
                                data : {
                                    action : 'thb_infinite_ajax',
                                    post_id : tempid
                                },
                                beforeSend: function() {
                                    id = null;
                                },
                                success : function(data) {
                                    //container.removeClass('thb-loading');
                                    $( ".thb-loading" ).remove();


                                        $(data).appendTo( '#infinite-article' );    


                                }
                            });

提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个...可能对你有帮助我改变了__tent函数

function thb_infinite_ajax() {
   $args = array(
        'p' => $previous_post->ID,
        'no_found_rows' => true,
        'posts_per_page' => 1
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

        $result = get_the_content($post->ID);
    endwhile; else : endif;
echo $result;
}