I use CMS WordPress, version 4.7.2.

There is an arbitrary field with $key=price and some value. Tasks to display the field in a specific place on the page. My code is:

<p><?php $page_id =the_ID(); get_post_meta($page_id, 'price', true);?>aaakv</p>

page_id prints, but the actual value of the derived field is not. I tried the options with get_metadata() and also did not help. Tell me, please, what could be the problem. Thank you.

    2 answers 2

    the_ID() displays the current post ID ON SCREEN .

    It is necessary so:

     <?php $page_id = get_the_ID(); $meta = get_post_meta($page_id, 'price', true); echo $meta; ?> 
    • Yes, it worked! Thank you - Alexander Sigida
    • For sure! And I didn’t pay attention to how $ page_id gets all the attention get_post_meta :) - SeVlad
    • it happens ......) - KAGG Design

    Somehow it should be:

     <?php $page_id = the_ID(); $key_price_values = get_post_meta($page_id, 'price', true); echo $key_price_values; ?> 
    • I tried, again displays the page id ( - Alexander Sigida
    • ID can not be. His function takes, not gives. Perhaps somewhere an error in the syntax or the names of variables / fields. - SeVlad