// Enter in the page id of your page that holds the custom fields <? query_posts('page_id=155'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <? // create a variable that stores the custom fields $meta = get_post_custom_values("manufacturer info"); // Use "shuffle" to create a new order each time the page loads $metas = shuffle($meta); $count = 0; // do a foreach loop to get the manufacturers foreach ($meta as $m) { // this is the work here...this takes each manufacturer and creates an array of their values. In this case $info = manufacturer name, $info[1] = manufacturer url, and $info[2] = manufacturer logo $info = explode(", ", $m); echo "<div>"; echo "<a href="" . $info[1] . "">"; echo "<img src="/wp-content/uploads/" . $info[2] . "" width="100">"; echo "</a>"; echo "</div>"; $count++; if ($count == 12) break; // This stops printing the array to the screen at 12 logos. So each time the page loads, 12 new logos will be loaded } ?> <? endwhile; else: endif; wp_reset_query();?>
Multiple Values Wordpress Custom Fields
So i had a client who needed to enter into their site a list of the manufactures that they sell in their store. In the past, i have set up a category called "Manufacturers" and then told them to create a new post for each one. The following client, just wanted the manufacturer name, logo, and website. So i created 1 wordpress page called "manufacturers" and created a custom field on that page called "manufacturer info." What is cool is that you can have more than one custom field with the same name on a page and wordpress will automatically create an array of them. I then bulk added the logos to the media library (after making them all the same size). So they were all pathed to /wp-content/uploads/file_name.jpg So i then added the info to the custom field in the following manner into the "value" field. Company Name, http://companyurl.com, company_logo.jpg and added about 50 manufacturers. So the client wanted 12 random manufacturers to be shown on their homepage in a certain section every time the page reloaded to keep it fresh. I added the following code to the hompage