Title, content etc from post id?

Hi,

I am using ajax to show page content like this:

$pageUrl = $_REQUEST['URL'];
$postid = url_to_postid( $pageUrl );         
$post = get_post($postid); 
$content = apply_filters('the_content', $post->post_content); 
echo $content;

But how could I show titles and acf fields?

I tried stuff like this (without success, only title is echoed)

<?php
$pageUrl = $_REQUEST['URL'];
$postid = url_to_postid( $pageUrl );         
$post = get_post($postid); 
?>

<h1><?php echo get_the_title($post); ?></h1>
<?php echo get_the_content($post); ?>
<?php echo get_the_field('testfield', $post); ?>

Anyone?

Nevermind, I got it working with this:

if ($post) {
setup_postdata($post); ?>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.