Home › Forums › Backend Issues (wp-admin) › Make custom fields visible
This is probably simple but I still can’t figure it out.
I’m trying to make some custom fields appear in my newspaper 6 theme.
I know I’m editing the right .php file as I can make simple html appear there but no matter what code I enter I’m not able to get the custom fields appear.
I tried the export code function but nothing happened. So I’ve also tried making custom fields visible by adding code like:
<?php echo get_field(‘company_name’);?>
<?php the_field(‘company_name’); ?>
<?php get_field(‘company_name’); ?>
As I’m a complete beginner I hope somebody can give me some pointers.
Kind regards
Lars
Some questions.
Is the content added for this field for a post, on an options page, or something else?
What template are you adding the code the_field('company_name')
to?
Is this inside “The Loop”? since you say you’re a beginner I will explain “The Loop”. the loop usually starts with something that looks like while(have_posts) :
and ends with end while;
Hi John,
and thanks so much for trying to help out.
The content for this field is for a post.
The template is Newspaper 6 by ThemeForrest. And I do believe it is inside a Loop – the name of the php. file is “loop single”. The starts of with an “if-statement” which also can be loop if my extremely basic php knowledge is correct?
I have attached a print screen of the code – as well as a printscreen of the setup in acf as well as inside the wp-post. So If I’m doing it correctly “VS Moda” should appear in the post – but nothing can be seen.
Kind regards
Lars
I don’t have access to that theme, and can’t say with 100% certainty, but I think where you’re trying to get the field is outside the loop.
My guess is that the post loop is actually in whatever file or code is loaded by this line.
<?php echo $td_mod_single->get_content(); ?>
Either that or there isn’t a real loop for this theme. Some theme authors do things in incorrect ways. It is possible to get the current post id without having a loop, but without having a loop you must always supply the post id because without it WP and ACF won’t figure it out for you.
Anyway, you can try this.
<?php
$queried_object = get_queried_object();
the_field('company_name', $queried_object->ID);
?>
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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 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.