Home › Forums › Front-end Issues › Post Object Causing Issue
I have an issue where the_permalink isn’t working when post_object is being used.
<?php the_permalink(); ?>
This should be the post link but is, instead, showing the current page URL on the frontend.
What have I missed?
Can anyone help?
Code below;
<?php
$args = array(
'post_type' => 'cpd',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'asc'
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<div id="cpd-items" class="p25top quiz-results">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="cpd-item quiz-result p25">
<div class="cpd-item-icon">
<i class="fa-light fa-file-lines"></i>
</div>
<div class="cpd-item-content">
<h5><?php the_title(); ?></h5>
<?php $post_object = get_field('quiz_results'); ?>
<?php if( $post_object ): ?>
<?php $post = $post_object; setup_postdata( $post ); ?>
<?php $postid = get_the_ID(); ?>
<?php echo $postid; ?>
<?php wp_reset_postdata( $post ) ; ?>
<?php endif; ?>
<p class="take-quiz-text">You have not yet taken this quiz. Please click the button below.</p>
<p class="p25top retake-quiz-button"><a>">Re-Take the Quiz</a></p>
<p class="p25top take-quiz-button"><a>">Take the Quiz</a></p>
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata( $the_query ); ?>
<?php endif; ?>
<?php } else { ?>
<?php } ?>
Where are you trying to use the_permalink()?
That aside, you have a query nesting issue.
Please see this topic and the topics that are linked to from there for an explanation of nested query issues. https://support.advancedcustomfields.com/forums/topic/nested-post-object-fields/
You must be logged in to reply to this topic.
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.