Get Custom Field Values
[resolved] Display Image Based on Checkbox Custom Field (2 posts)

  1. kmelkight
    Posted 5 years ago #

    I am building a shop directory. I have set up a checkbox-type custom field for Shop Type (choices are: brick and mortar or internet; either or both could be chosen) and a select-type custom field for Shipping (choices are: domestic only, limited international, worldwide). I want to display the results after the shop's title as icons rather than text. And for Shipping, a globe would be displayed if worldwide was selected, otherwise there'd be no image.

    I understand how to output a series of values using Get Custom Field Values, but displaying an image based on these criteria has me stumped. I'm open to the possibility of using different custom fields to make this easier. Is this just something that's beyond this plugin?


  2. Scott Reilly
    WordPress & Plugin Dev
    Plugin Author

    Posted 5 years ago #

    I presume you're already comfortable modifying your template file to utilize one of the Get Custom Field Values functions?

    The plugin can certainly do what you're requesting.

    Here's an example of how to display a globe icon if a post has a custom field "Shipping" with a value of "worldwide". If any other shipping value is present for the post, or no shipping is defined, nothing is shown.

       if ( c2c_get_custom( 'Shipping' ) == 'worldwide' ) {
          echo c2c_get_custom( 'Shipping', '<img src="/wp-content/images/globe.png" alt="Worldwide shipping available" />' );

    You'll of course want to customize the img tag to point to your image.

    Your request suggests some new functionality I can add to the plugin to facilitate this sort of thing, so look for it in the near future.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic