I am trying to load a ACF Field from a page to my 404.php but i cannot get it to work.

get_post_field works fine but get_field does not


 * The template for displaying 404 pages (not found)
 * @link https://codex.wordpress.org/Creating_an_Error_404_Page
 * @package test

$post_id = 6018; // Post ID 
$acf_field = get_field('text', $post_id); // get acf field 'text' from post

<div id="primary" class="content-area container">
    <main id="main" class="site-main">

        <section class="error-404 not-found">
            <header class="page-header">
                <h1 class="page-title"><?php echo get_post_field('post_content', $post_id); ?></h1> <!-- Does something -->

            <div class="page-content">
                <?php echo $acf_field ?> <!-- Does nothing -->


  • You're sure text is the full name of the field, and it contains data? Have you tried var_dump($acf_field) in case it's not just a string? – WebElaine Nov 21 '19 at 16:17
  • var_dump returns NULL which is really weird. – Evolis Nov 22 '19 at 13:10
  • also get_fields($post_id) returns bool(false) – Evolis Nov 22 '19 at 13:11
  • I'd check the database to make sure that post ID is valid (exists in wp_posts). If so, I'd then check the postmeta table to see if it contains any fields for that post ID. – WebElaine Nov 22 '19 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.