The Design Canopy Forums » WP Contact Manager

How to Display a Checklist

(7 posts)

  1. Hi, I have a custom field, called "Dining", with three options: "Breakfast" "Lunch" "Dinner"

    Everything shows up fine on the admin page and the new contact can check whether it is available for Breakfast, Lunch and/or Dinner. But not having luck getting those options to display.

    Tried: <?php echo get_post_meta($post->ID, "Dining", true); ?> and <?php echo get_post_meta($post->ID, "Dining", false); ?>

    Also tried: <?php echo get_post_meta($post->ID, "Breakfast, Lunch, Dinner", true); ?>

    Posted 6 days ago #
  2. It's a bit more complicated than I thought. Here's the code:

    <h3 class="site-subtitle">Availability:</h3>
    <ul>
    <?php
    	$availabilitytimes = get_post_custom_values("Availability");
    	foreach ( $availabilitytimes as $availabilitytime )
    	{
    		echo '<li>'.$availabilitytime.'</li>';
    	}
    ?>
    </ul>

    You can see how this works at the demo site on Test Person's details.

    Some things to note:

    • You have to use the get_post_custom_values() function as opposed to the get_post_meta() function.
    • Note the plural vs. single formatting of the variables in the for_each loop. I don't have the programming expertise to really explain this, but I think they need to have that relationship for the array to work properly. But maybe I'm wrong? Unfortunately I don't really know!

    Let me know if you have any more problems.

    See this article for more reference: WordPress Codex: Using Custom Fields

    Posted 5 days ago #
  3. I forgot to mention that "Availability" was the name I gave to my Checkbox List in the Custom Write Panel interface with my options being Breakfast, Lunch and Dinner.

    Posted 5 days ago #
  4. Thanks so much David. Works perfect, and opens all sorts of possibilities w/ WordPress. Part of what I love about WordPress is that there is such a strong creative community -- this isn't the first time somebody has solved a big problem for me and I'm happy to send thank$ when I can.

    For the record, I didn't have to mix plural/single. My field name is Dining, and this displays the results:

    <?php
    	$dining = get_post_custom_values("Dining");
    	foreach ( $dining as $dining )
    	{
    		echo '<li>'.$dining.'</li>';
    	}
    ?>
    Posted 4 days ago #
  5. Nothing's ever simple...

    Works fine for Contacts that make choices from the checklist. For those that don't, we get:

    Warning: Invalid argument supplied for foreach() in /home/.iconium/msky/enviro.us/orcasbiz/wp-content/themes/wp-contact-manager-0/single.php on line 43

    Line 43 is: foreach ( $dining as $dining )

    Also, the Edit This button from another thread works great for me.....

    Posted 4 days ago #
  6. Yes, good call, we would need a check to see if they have those options. This worked for me:

    <?php
    	$availabilitytimes = get_post_custom_values("Availability");
    	if ( $availabilitytimes != "" )
    	{
    ?>
    	<h3 class="site-subtitle">Availability</h3>
    	<ul>
    	<?php
    		foreach ( $availabilitytimes as $availabilitytime )
    		{
    			echo '<li>'.$availabilitytime.'</li>';
    		}
    	?>
    	</ul>
    <?php
    	}
    	else {}
    ?>
    Posted 4 days ago #
  7. works perfect...........

    Posted 4 days ago #

RSS feed for this topic

Reply

You must log in to post.