I am currently working on a single page website. I am trying to retrieve the page content via AJAX.
The page URL is http://mylocalserver/sad/wp/clients
.
$.get( 'http://mylocalserver/sad/wp/wp-admin/wp-ajax.php',
{
'action' : 'retrieve_content',
'page_title' : 'clients'
}, function( response ){
if ( !response.error ) {
alert ('AJAX request made! The post title is ' + response.post_title );
} else {
alert ('error: ' + response.error );
}
});
in my php functions.php
function retrieve_content(){
$page = get_page_by_title( 'clients' );
$content = apply_filters('the_content', $page->post_content);
var_dump($content);
exit();
}
It says Page not found, whereas if I visit the page via URL the content appears. I have hard coded the page title in the PHP function as-well.