2

I have custom fields defined on wordpress in which I have entered an episode number for each post I have written. I want to use this value in a form, but I need to keep the form code all the same and just call it using shortcode in each post since there are way too many posts to edit manually.

I have tried

<input type="hidden" name="Episode" value="<?php the_meta(); ?>"/>

to set the value of Episode inside the form as the value for that specific post, but the php code is still able to be seen on the page source code so it is not going through. Is there a workaround?

3 Answers 3

3

You have to echo the response.

<input type="hidden" name="Episode" value="<?php echo the_meta(); ?>"/>

Of course you can also use print functions.

Sign up to request clarification or add additional context in comments.

3 Comments

It still shows up in the source code as <input type="hidden" name="Episode" value="<?php echo the_meta(); ?>"/> , as if the PHP isn't being called
Then you may have a problem with your the_meta() function. Or the page isn't being interpreted as PHP which is entirely possible depending upon how your CMS is handling page generation.
When I put <?php echo the_meta(); ?> in a post it displays the correct data, though
3

Although the above answer(by jjs9534) is true, you typically need to echo the_meta, it is not the problem, the problem is that your files are not being parsed by PHP, you either need to rename your extensions to .php or mess around with .htaccess(on Unix) server web.config (on Windows) to add the extension you are using for your pages to be parsed as a php file... so in .htaccess, to parse .htm or .html files as PHP you would add:

AddHandler application/x-httpd-php .html .htm

3 Comments

Thanks, it still isn't working though. If it's of any help, I've got a function that calls the form using a shortcode. I don't think it matters though as the source code shows everything, only it is not executing the php function.
I've found a half solution. Using the shortcode meant it wouldn't work, but copying the whole table in place of the shortcode works. Is this because the shortcode is calling a function itself?
Yes, you would need to run an eval() on the variable holding HTML/PHP with the shortcode before you output it to your display page.
2

You need to echo the value of the_meta() for it to appear on your page.

Try this

<input type="hidden" name="Episode" value=<?php echo "'" . the_meta() ."'"; ?>/>

Edit: I changed the code slightly. Try that.

6 Comments

It still shows up in the source code as <input type="hidden" name="Episode" value="<?php echo the_meta(); ?>"/> , as if the PHP isn't being called
@Serj is right, there is something else wrong here. Do other PHP scripts run?
All other PHP scripts are running. This is very strange.
I've found a half solution. Using the shortcode meant it wouldn't work, but copying the whole table in place of the shortcode works. Is this because the shortcode is calling a function itself? Just tried your code and I get Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
Do you have an unclosed quote somewhere else in the html on the page?
|

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.