Site icon Hip-Hop Website Design and Development

Apply filters when loading publish through ajax

Have been attempting to unravel this for couple of hours already. This is the case: I am making a plugin that separates the posts into pages utilizing the <!--nextpage--> tag. It really works effective however I wish to change the pages through ajax.

Beneath I am exhibiting how I do it however when the content material is returned the_content filters are usually not utilized and plenty of functionalities are usually not exhibiting (the pagination which I added and doubtless theme and different plugins performance that’s connected to the publish).

This is my ajax perform:

jQuery(doc).prepared(perform($) {
    $(doc).on('click on', '#upp-pagination a', perform(occasion) {
        occasion.preventDefault();

        var web page = $(this).mother or father().attr('class').exchange(/D/g, '');
        var postID = $('#upp-pagination').attr('class').exchange(/D/g, '');

        $.ajax({
            url: upppagination.ajaxurl,
            kind: 'publish',
            knowledge: {
                motion: 'load_page',
                web page: web page,
                postID: postID
            },
            success: perform (consequence) {
                var newPage = consequence;

                $('div.entry-content').html(newPage);
            }
        });
    });
});

And that is the perform on the back-end that returns the pages:

public perform loadPage() {
    $postID = $_POST['postID'];
    $web page = $_POST['page'];

    $publish = get_post($postID);

    $content material = $post->post_content;

    if ( false !== strpos( $content material, '<!--nextpage-->' ) ) {
            $content material = str_replace( "n<!--nextpage-->n", '<!--nextpage-->', $content material );
            $content material = str_replace( "n<!--nextpage-->", '<!--nextpage-->', $content material );
            $content material = str_replace( "<!--nextpage-->n", '<!--nextpage-->', $content material );

            // Ignore nextpage initially of the content material.
            if ( 0 === strpos( $content material, '<!--nextpage-->' ) )
                    $content material = substr( $content material, 15 );

            $pages = explode('<!--nextpage-->', $content material);
    } else {
            $pages = array( $post->post_content );
    }

    $web page = $pages[$page - 1];

    $response = apply_filters('the_content', $web page);
    wp_send_json($response);
}

Am I utilizing the proper strategy right here and the way I can apply the filters? Any concepts?