Use get_post_meta function, some examples could be seen there too.
Thank you for the reply. To be honest, I’ve already looked at that post, and I don’t really understand what Im looking at, or how I would use the examples. I don’t have a coding background, other than very basic html. Hence, I was hoping someone could show me how / what I need to use.
I don’t know where you are trying to insert those fields. Also, I don’t know IDs of your fields (Service Used or Service URL are not correct ones, they shouldn’t be separated by spaces).
Hey,
Im trying to insert the things into my single.php file, within the loop. The field names are as follows: ‘service_used’ and ‘service_url’
Thanks again. π
Safe example of code:
$service_used = get_post_meta(get_the_ID(), 'service_used_field', true);
$service_url = get_post_meta(get_the_ID(), 'service_url_field', true);
if($service_used && $service_url) :
echo '<a href="' . $service_url . '">' . $service_used . '</a>';
endif;
Oh, I guessed your fields π
Try that code and report if it works, please.
OK I entered that into my post, but nothings showing up. (Emptied my cache, tried with Firefox, Safari and Chrome).
Heres the code Im using.
single.php:
<? $service_used = get_post_meta(get_the_ID(), 'service_used_field', true);
$service_url = get_post_meta(get_the_ID(), 'service_url_field', true);
if($service_used && $service_url) :
echo '<a href="' . $service_url . '">' . $service_used . '</a>';
endif;?>
In the portfolio.php custom post type page that came with my theme…
'service_used' => Array('type' => 'text', 'description' => __('Service', 'themeton'), 'title' => __('Service', 'themeton')),
'service_url' => Array('type' => 'text', 'description' => __('Service URL', 'themeton'), 'title' => __('Service URL', 'themeton')),
Can you see anything wrong with that?
Sorry, my bad:
$service_used = get_post_meta(get_the_ID(), 'service_used', true);
$service_url = get_post_meta(get_the_ID(), 'service_url', true);
if($service_used && $service_url) :
echo '<a href="' . $service_url . '">' . $service_used . '</a>';
endif;
There must be something weird going on with my theme or something. No matter what I do, it’s just not showing up. I know Im editing the right page, as other changes I make to it show up just fine. But nothings showing up with regards to the custom fields.
It ‘should’ be showing up above the Date on the right hand column at the following URL….
http://metalpotato.com/portfolio/techno-chimp/
Try this code (it is not safe, but should output fields if they do exist):
$service_used = get_post_meta(get_the_ID(), 'service_used', true);
$service_url = get_post_meta(get_the_ID(), 'service_url', true);
echo '<a href="' . $service_url . '">' . $service_used . '</a>';
Still nothing. I honestly don’t get it, as the custom fields show up in the admin, and are filled out (see pic). But the output is not showing up on the front end.
http://postimg.org/image/43dv3pvi3/
Probably, your custom fields have some other names. You will need to get them.
Hey, I asked the person who created the theme about it, he made a small modification to the code you gave me, and it worked perfectly.
This is what worked:
$service_used = get_field("service_used");
$service_url = get_field("service_url");
echo '<a href="' . $service_url . '">' . $service_used . '</a>';
Seems like the developer of your theme is using 3rd party framework or plugin as get_field()
is not an in-built WordPress function. Great to hear that everything has worked out.
Ahh that now makes sense. Im not that great with code, so I was stabbing in the dark. Either way, thanks very much for your help. It was very much appreciated. π