0

I'm starting a WordPress website where I need the template to do a few things differently depending on the "Custom Fields" I set for each Page. The easiest way for me to do this is to have php values of the custom fields I set on those pages that I can then use throughout template files.

The closest thing I have found in WP documentation is:

<?php $key = "Random_Key_I_Need_Here" echo get_post_meta($post->ID, '$key', true); ?>

This echos the value of the key I need, but what I need is that value in a PHP value instead, so that I can use it throughout the template to dictate certain tags/content. Basically, how do I get exactly what the above script is doing in a PHP value instead of echo'ing it?

Thanks

1 Answer 1

1

You can just make it a variable.

$key = "Random_Key_I_Need_Here";
$metaValue = get_post_meta($post->ID, '$key', true);
Sign up to request clarification or add additional context in comments.

1 Comment

I got so warped into trying to learn all this WordPress stuff.. I needed to take a step back. Whew. Thanks for bringing common sense back to me!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.