Can't display custom fields in my custom post type page
-
Hi, I’m a CPT newbie.
I’ve made a custom post type named “event” in CPT UI and added some fields to it using custom fields.
Then I’ve created a page named “single-event.php” in my theme’s folder and added the following code, but nothing is being displayed and also I can’t see any errors in my logs.What I’m doing wrong?
(Fields ‘event_name’ and ‘start_date’ are my generated fields using custom fields)
<?php
/**
* Template Name:events
*
* @package sparkling
*/get_header(); ?>
<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>
<?php
$args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo ‘<div class=”entry-content”>’;
the_field(‘event_name’);
the_field(‘start_date’);
echo ‘</div>’;
endwhile;?>
</main><!– #main –>
</div><!– #primary –><?php get_sidebar(); ?>
<?php get_footer(); ?>Thanks,
Kasra
- The topic ‘Can't display custom fields in my custom post type page’ is closed to new replies.