Fatal error: Call to undefined function get_post()

I’m new on wordpress and I’m trying to create my first website, I have an index.php page with about link, which will get about author content from created page (post) inside wordpress dashboard with name about. I’m using magnific popup plugin for poups.. I have about.php which includes content of about page like this

about.php

Read More
<?php 
        $pageid = 2; // 2 is the id of about page/post
        $about = get_post($pageid);
    ?>

<div id="custom-content" class="white-popup-block" style="max-width:600px; margin: 20px auto;">

    <h3><?php echo $about->post_title; ?></h3>
    <style>
    #custom-content img {max-width: 100%;margin-bottom: 10px;}
    </style>
    <div class="image-container pull-left">
        <img src="<?php echo get_field( "image", $pageid ); ?>">
    </div>
    <h4><?php echo get_field( "brief", $pageid ); ?></h4>
    <p>
    <?php echo get_field( "brief_lines", $pageid ); ?>
    </p>
    <div class="about-content">
        <?php echo $about->post_content; ?>
    </div>
</div>

index.php

<a href="<?php echo get_template_directory_uri(); ?>/about.php" class="morelink pull-left text-ajax-popup">read more</a>

footer.php

$('.text-ajax-popup').magnificPopup({
        type: 'ajax',
        alignTop: true,
        overflowY: 'scroll' 
});

after click on the link I got this error

Fatal error: Call to undefined function get_post()

Is there files could I include inside about.php ? what is the problem ?

Related posts

Leave a Reply

3 comments

  1. You’re not loading WordPress.

    You need to build a theme instead of putting PHP files in the root directory. WordPress will setup the environment and then load your theme making functions like get_post() available to you without you having to include core files in every PHP file you create.

    Take a look at how the default themes are built to get a better understanding of what’s involved.