showing fields in theme not working

This topic contains 3 reply and 2 voices, and was last updated by RJ 10 years, 4 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
July 22, 2014 at 10:41 am 23928
RJ Here is my code: echo get_post_meta( $post->ID, 'sub_category', true ); I've surrounded it with the appropriate php open and close tags and the 'sub-category' is the meta key from my form, but it displays nothing. What am I doing wrong? Thanks for your help!!
July 22, 2014 at 2:32 pm 23947
Sk Sk

Hello RJ,

The code looks ok.
please check is the meta have value?
re-check is the running in the loop?
re-check the variable $post->ID, is it works?
Re-check meta key sub_category.

if not work, use var_dump() rather than echo to check what it returns?

Thank you.

July 23, 2014 at 11:43 am 24005
RJ RJ

I’ve checked to make sure that the meta has a value and also checked that the meta key matches with the one I specified. The code is running in the loop.

When I do the var_dump, this is what I get: bool(false)

This is the complete snippet of code that I have running in the loop at present:

echo get_the_term_list( $post->ID, ‘county’, ‘County: ‘, ‘, ‘, ” );
echo get_the_term_list( $post->ID, ‘city’, ‘City: ‘, ‘, ‘, ” );

echo get_post_meta( $post->ID, ‘sub_category’, true ) . “This is the category”;
$a = get_post_meta( $post->ID, ‘sub_category’, true);
echo var_dump($a);

The first two items (county and city) display perfectly so I know that $post->ID works.

I cannot figure out why the meta from my form isn’t working though. It’s really important that we get this fixed because I am trying to customize my template for the post and this seems to be the only way to do that.

July 27, 2014 at 1:46 pm 24175
RJ RJ

Ok, so after some experimentation, I have found that for some reason post->ID won’t work. Instead I have to use get_the_ID(). Below is what I ended up with. Is there some reason that post->ID works perfectly for my custom taxonomies, but I have to switch to get_the_ID() for the form’s custom fields?

echo get_the_term_list( $post->ID, ‘county’, ‘County: ‘, ‘, ‘, ” );
echo get_the_term_list( $post->ID, ‘city’, ‘City: ‘, ‘, ‘, ” );
echo “Type of Offer: ” . get_post_meta( get_the_ID(), ‘sub_category’, true );

Thanks!

Viewing 3 Posts - 1 through 3 (of 3 total)