I’m using a custom field called “video” for getting and showing a Youtube ID on a WP page.
I I create a new page, the custom field works without problems.
When I try to edit the “Video” custom field on an already existent page, the custom field will be updated in the backoffice but not shown in the frontend!!
After I save the changes, the “video” field shows the new ID but in the Frontend i have NOTHING!!!
I also checked in the database, and the custom field is populated.
So, why I have no output in the page?
I’m using this code:
tried also with
and still nothing
If you can confirm that the value does change on the backend, then the value is correctly saving / loading to the DB.
The issue could be related to caching perhaps?
Also, where are you using the the_field code? In a single.php file?
Are you using it within a loop?
Yes, I confirm that the value does change in the backend and also saved to DB (checked using phpmyadmin)
What type of cache do you mean? If you mean the browser cache I cleared it and tried on different browsers/machines.
I’m using the code on a custom page.php outside the loop.
The cache I am referring to is page / database cache which would require a Cache plugin to work.
If your code is outside the loop, it is possible that ACF deos not understand which post to load the data from.
Can you move the code within the loop to test this?
It is possible that you have a plugin / theme code which is modifying the post_id which ACF uses to load the value from.
Can you debug the global $post object?
<?php global $post; echo '<pre>'; print_r($post); echo '</pre>'; die; ?>
Place the above code in your single PHP file. Does the $post object contain the correct ID and title?
I found the problem:
This happens only if the page has subpages! The subpages also have the same “video” custom field.
If the page does’t have any subpage, the video shows up.
I resolved the problem by putting this code after the loop that shows up a list of subpages:
<?php wp_reset_postdata(); ?>
<?php wp_reset_query(); ?>
The topic ‘Custom fiels not shown/updated in existent pages’ is closed to new replies.
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 PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.