Hi,
my task/problem is similar to this one:
trying to get the fully rendered content of a page with ajax call to wordpress api.
but somehow i am not able to get it done.
my current code:
add_action('wp_ajax_loadmore', 'loadmore_callback');
add_action('wp_ajax_nopriv_loadmore', 'loadmore_callback'); // For non-logged-in users
function loadmore_callback() {
// Ensure the AJAX request came from WordPress and is valid
check_ajax_referer('loadmore_nonce', 'security');
// Get the page ID from the AJAX request
$page_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0;
$response = array();
if ($page_id > 0) {
// Use WP_Query to fetch the page by ID
$query_args = array(
'page_id' => $page_id,
'post_type' => 'page',
'post_status' => 'publish'
);
$query = new WP_Query($query_args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
// Start output buffering to capture the page content
ob_start();
// Get the page content
the_content();
// Capture the output and end buffering
$page_content = ob_get_clean();
// Send the page content as the response
$response['success'] = true;
$response['html'] = apply_filters('the_content', $page_content); // Allow shortcodes and other filters
// Break the loop after fetching the first matching page
break;
}
// Reset the post data
wp_reset_postdata();
} else {
$response['success'] = false;
$response['message'] = 'Page not found or not published.';
}
} else {
$response['success'] = false;
$response['message'] = 'Invalid page ID.';
}
// Send the JSON response
wp_send_json($response);
}
What i get as response is content only, without rows, columns and other stuff generated by BB modules etc. what am i missing here, hope someone can point me in the right direction!