First things first – YOU ARE NOT ON THE RIGHT PATH IF YOU ARE MODIFYING CORE FILES. If it’s not in wp-content
, DO NOT MODIFY IT, especially if you can honestly say “I just do not have the PHP skills necessary to XXXX”. STAY OUT OF CORE FILES, PERIOD. I’m not being mean, I’m saving you the hassle of losing your changes with each WordPress update, plus the ire of WordPress developers as a whole.
You’re going to have a problem the way you’re going about it. From the sound of it, you’re trying to call get_field()
in the header outside the loop, but somehow wanting it to know where in the loop it is.
Some explanation that might help: custom fields are attached to specific pages/posts (as you already know). This means that get_field()
will return values according to the current object in $post
– in the header, that’s the current page. Not sure what the object in $post
is at any given point? Use this code chunk where you want to know:
<pre>
<?php print_r($post); ?>
</pre>
You can also swap $post
with $post->ID
to see which post it’s working on (especially useful for seeing what posts are pulling up in a loop).
So, you’ll need to register whether or not a piece is sold by checking in the loop, then perhaps attach a CSS class to the output in the loop, and use CSS to show/hide that bit.
If you’re trying to do it by hooking into a function (for attachment override, for example), then put that hook into functions.php
. You can modify or override core functions in functions.php
with filters and hooks – check the Codex for more info.