Home › Forums › Front-end Issues › fields in category -> post still not showing up
Original problem:
Theme: Mobile Friendly
WP version: 4.9.1
Problem: I have a created a field group (ACF) that has (2) fields; a) text (Mattaymom) and b) number (class_number) , and edited the single.php file, see below. When I view the single post this information (2) and other information (wp-textbox) displays OK. However, when the post is viewed by the user clicking on a category that links to the same post, this information does not display (2), and only the text from the wp-textbox. I would like to use more fields in the future once I can resolve this issue.
<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>
<?php while ( have_posts() ) : the_post(); ?>
<H4>Matthayom/Class/Feedback<H4>
<H5>Matthayom <?php the_field( ‘matthayom’ ); ?><br/><H5>
<H5>Class <?php the_field( ‘class_number’ ); ?><br/><H5>
<H5><?php the_field( ‘comment’ ); ?><br/><H%>
<?php get_template_part( ‘content’, ‘single’ ); ?>
Original reply:
Hi Simon,
Thanks for the email.
All the template functions (get_field, the_field, etc) can be used to load values from another post, however, a second parameter is required to target the post.
Each post has a unique ID which can be found in the URL when editing or found via code such as $post->id.
I believe when you are clicking the categories link it directs you to the category page instead of the post itself.
Kindly try:
<div id=”primary” class=”content-area”>
<main id=”main” class=”site-main” role=”main”>
<?php while ( have_posts() ) : the_post(); ?>
<H4>Matthayom/Class/Feedback<H4>
<H5>Matthayom <?php the_field( ‘matthayom’, $post->ID ); ?><br/><H5>
<H5>Class <?php the_field( ‘class_number’ , $post->ID); ?><br/><H5>
<H5><?php the_field( ‘comment’, $post->ID ); ?><br/><H%>
<?php get_template_part( ‘content’, ‘single’ ); ?>
Let me know how it works for you.
second reply: still not working?
Thank you for your prompt reply. I inserted the code you sent to replace my code into the single.php file, however the issue still remains. What you said in your explanation made a lot of sense, however I still cannot trouble shoot the problem, from looking on the internet and on your support site.
Thank you in advance.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.