[wp-hackers] Accessing custom fields in a post

Brian Fidler fidler.brian at gmail.com
Tue Mar 30 08:57:47 UTC 2010


Nevermind, I figured it out.

I added the following to my functions.php file:

function get_custom_field_value($bfiKey, $bPrint = false) {
   global $post;
   $bfiValue = get_post_meta($post->ID, $bfiKey, true);
   return $bfiValue;
}

and I added this to my Page template:

<?php
    if ( function_exists('get_custom_field_value') ){
      $myPrice = get_custom_field_value('price', true);
      $myShipping = get_custom_field_value('shipping', true);

      $myTotal = $myPrice + $myShipping;

      echo "<h3>Price: $" . $myPrice . "</h3>";
      echo "<h3>Shipping: $" . $myShipping . "</h3>";
      echo "<h3>Total: $" . $myTotal . "</h3>";
   }
?>


[image: brian fidler interactive] <http://www.brianfidler.com>
email: interactive at brianfidler.com
phone: 602.758.4733
[image: View Brian Fidler's profile on
LinkedIn]<http://www.linkedin.com/in/brianfidler>


On Tue, Mar 30, 2010 at 1:12 AM, Brian Fidler <fidler.brian at gmail.com>wrote:

> I have a number of Page sections on my site where I am using a Page as a
> product. I've added a custom field for Image, a custom field for Price and a
> custom field for ShippingCost. There are separate Page sections for
> Paintings, Prints, and Misc items where the child items of that section are
> the actual product. Some items in each section have the associated Price and
> Shipping but not all items.
>
> How can I access the data in a loop so that I can display a list of all
> pages/products that include Image, the Price, and the ShippingCost
> associated with the product/page?
>
> So for example I might display 2 items from Paintings (w/12 total items), 5
> items from Prints (w/8 total items) and 4 items from Misc (w/16 total
> items).
>
> I hope that makes sense, let me know if it doesn't.
>
> thanks,
> brian
>
>
> [image: brian fidler interactive] <http://www.brianfidler.com>
> email: interactive at brianfidler.com
> phone: 602.758.4733
> [image: View Brian Fidler's profile on LinkedIn]<http://www.linkedin.com/in/brianfidler>
>
>


More information about the wp-hackers mailing list