• Greetings

    I’m playing with the ‘add_meta_boxes’ to understand how it works and how different it is from custom field

    when I look at the database, it seems both are the same value

    it is only a difference visual aspect on the post page

    I have seen there is also different function, but to me they return the same

    let say I have add an extra box named ‘price’
    what is the difference between

    $custom = get_post_custom($post->ID);
    $price = $custom["price"][0];

    and

    $price2 = get_post_custom_values('price',$post->ID,);

    and
    $price3 = get_post_meta($post->ID, 'price', true);

    to me they pull out the same date, is there performance difference? is one better than the other to use? if I have several ‘custom field’ to retrieve, is that best performance white to use get_post_custom? is that generating only one query while get_post_meta make a query per request?

    thank you in advace

    Steffy

Viewing 7 replies - 1 through 7 (of 7 total)
  • get_post_meta
    – fetches all values or the first value for the custom field with the provided key.

    get_post_custom
    – fetches all the post’s custom field keys and values

    get_post_custom_keys
    – fetches all the post’s custom field keys

    get_post_custom_values
    – fetches all the post’s custom field values with the provided key

    If you want the value(s) of a particular key then use get_post_meta, set the third parameter to true if you want the first value, and leave it out (or set to false) if you want multiple values.

    NOTE: All the functions above, with exception to get_post_meta() return all a post’s meta data(unless you’re defining the key), that includes internally used post meta that you wouldn’t typically want to display. Unless you want to grab meta data for more then one key, use get_post_meta for singular or multiple values..

    Thread Starter freeriders

    (@freeriders)

    cristal clear Mark

    thank you VERY much for your explaination

    if I well understand, if I have 10 custom fields to retrieve, if I use get_post_meta() for each custom field it will make 10 database call and if I use get_post_custom it will make only 1 call and store them all in a variable

    thank a munch bunch

    khhm, not really clear to me.. i’ve been dealing with custom fields and custom meta boxes for several days only trying to build a very simple and static availibility calendar for a property as a custom post type using custom fields and multicheck boxes (if available on a certain day, the checkbox is checked), etc.

    what i am trying is to show/display all values of a custom field key, like :

    <?php $ac_january_values = get_post_custom_values('ac_january'); foreach ( $ac_january_values as $key => $value ) { echo "$value "; } ?>

    but i am getting those values in a reverse/bad order, like : 02 01 05 , etc. How to re-order those values so to make them show as 01 02 03 04 05, etc. and how to display even ‘unchecked’ boxes??

    Another thing:
    using

    <?php // elevator
    	if ( get_post_meta($post->ID, 'feat_elevator', true) ) :
    	echo 'Elevator:';
    		echo get_post_meta($post->ID, 'feat_elevator', true);
    	else :
    	echo 'Elevator:';
    	echo 'No';
    	endif; ?>

    i am getting, when checked:
    Elevator: on

    How to change that ON to YES or even better – how to make it be displayed as an icon or an image instead ??

    Thanks so much!!

    in fact, instead of echoing get_post_meta($post->ID, 'feat_elevator', true); just echo ‘yes’ , but i’m still struggling trying to replace it with an icon….

    in fact, icons/images solved, but still wondering how to show unchecked boxes and how to have a good display order… it’s really exciting learning php and wordpress… thanks again!!

    just to be sure that i have found a decent solution, here is how i have solved my icon/image problem

    echo '<img src="';
    echo get_bloginfo('template_directory');
    echo '/images/tick.png';
    echo '" />';

    or maybe there is another and better way?

    or is it better to use get_template_directory_uri(); ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘difference between get_post_custom and get_post_custom_values and get_post_meta’ is closed to new replies.