Home Forums Plugin Support WP User Frontend Pro showing fields in theme not working

This topic is: resolved

This topic contains 3 replies, has 2 voices, and was last updated by  RJ 4 years, 10 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #23928

    RJ
    Participant
    Post count: 21

    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!!

    #23947

    Sk
    Moderator
    Post count: 371

    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.

    #24005

    RJ
    Participant
    Post count: 21

    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.

    #24175

    RJ
    Participant
    Post count: 21

    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 4 posts - 1 through 4 (of 4 total)

The topic ‘showing fields in theme not working’ is closed to new replies.