First, you made a really, really silly typo:
'ajaxurl' => admin_url( 'admin-ajax.php' ),
.....
url: funnel_ajax.ajax_url,
ajaxurl
!= ajax_url
. So your Admin AJAX request is not returning a full HTML page. You’re not even hitting the AJAX file!
However, this is still completely the wrong way to go about this
I was going to suggest that you instead use the REST API which is much easier and foolproof, and to write a custom endpoint using register_rest_route
to give you a pretty URL such as example.com/wp-json/richerimage/v1/dnafunnel
, but you don’t need to.
In fact, you don’t even need an AJAX handler or an endpoint. Just use the one that core gives you.
First, register the post meta so it appears in the REST API responses:
PHP:
$args = array(
'type' => 'string',
'description' => 'DNA Funnel Info thing',
'single' => true,
'show_in_rest' => true,
);
register_post_meta( 'post', 'dna_funnel_info', $args );
Then retrieve the desired post, e.g. example.com/wp-json/wp/v2/post/123
where 123 is the ID of the post you wanted. The JSON response will contain the content in its fully rendered form, title, taxonomies, etc, including a meta section with all the meta keys you registered.
If your post ID is for a CPT, make sure show_in_rest
is set to true when it’s registered, and replace /post/
with the relevant endpoint for that CPT
Or better yet, use PHP:
add_filter( 'the_content', function( $content ) {
// append post 123's content to the end
return $content . get_the_content( '', '', 123 );
} );