Home › Forums › Front-end Issues › Problem returning post object data › Reply To: Problem returning post object data
Here is an example of useage in a loop. It’s not particularly long so I’m just pasting it here. Relevant code is on line 64, JSON is attached.
<?php
/*
Template Name: Current Semester
*/
get_header('courses');
$semester = get_field('current_semester', 'option');
?>
<div class="content width" role="main">
<div class="page">
<?php get_sidebar('courses'); ?>
<section class="content-container">
<div id="regular-content">
<!-- Undergraduate -->
<?php
$ud_args = array(
'post_type' => 'courses',
'taxonomy' => 'courses-category',
'field' => 'term_id',
'terms' => $semester,
'meta_query' => array(
array(
'key' => 'course_number',
'value' => array( 100, 199 ),
'type' => 'numeric',
'compare' => 'BETWEEN'
)
),
'meta_key' => 'course_number',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'posts_per_page' => '60'
);
$ud_query = new WP_Query($ud_args);
if($ud_query->have_posts()) : ?>
<h2 class="course-level-header">Undergraduate</h2>
<div class="courselist_content">
<?php while($ud_query->have_posts()) :
$ud_query->the_post(); ?>
<article id="post-<?php the_ID(); ?>" class="group course-list-wrapper">
<header class="index-header">
<h1 class="course-title">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'thales' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
<?php the_field('language_prefix'); ?> <?php the_field('course_number_prefix'); ?> <?php the_field('course_number'); ?><?php the_field('course_number_suffix'); ?>: <?php the_title(); ?>
</a>
</h1>
</header><!-- .entry-header -->
<div class="course-content">
<p class="section-spacing">
<?php the_field('timeframe'); ?> <span class="course-details"><?php the_field ('location'); ?></span>
<span class="course-details"><b>Instructor: <?php $post_object = get_field('instructor', $post->ID); ?> <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo $post_object->post_title; ?></a></p>
</b></span>
</p>
<?php the_content(__(' » read more »'));?>
<p class="section-spacing">Course Catalog Number: <?php the_field ('ccn'); ?></p>
</div><!-- .course-content -->
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</section><!-- #content-container -->
</div>
</div>
<?php get_footer(); ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.