WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Magic Fields] – If Field Is Empty – Don’t Show It!

[Plugin: Magic Fields] – If Field Is Empty – Don’t Show It!

  • Hi there,

    I’m using the Magic Fields plugin and I was wondering how I can do PHP and make sure, if the field is empty, not to show it.

    Right now, in Internet Explorer, it’s showing a box with a red X in it for my images, and some Testimonials don’t have images in right now.

    Here’s my code for displaying my fields as a group:

    <?php
    		$alltestimonials = get_group('testimonials');
    		foreach($alltestimonials as $testimonials) {
    			echo "<blockquote><cite>";
    			echo $testimonials['person_location'][1]."</cite>";
    			echo "<img class='aligncenter' src=' " .$testimonials['testimonial_photo'][1]['t']. " '>";
    			echo $testimonials['preview_snippet'][1]."<div class='toggle'>";
    			echo $testimonials['rest_of_testimonial'][1]."</div>";
    			echo "</blockquote>";
    			}
    	?>

    Is it something like if(!empty? That’s all I know lol…

    I appreciate any help 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • Bump.

    Hello. I have been looking for something like this too, and after about 2 hours of searching google and trial and error I think I have found the solution.

    if ( get(‘field_name’,TRUE) ) {
    do this ;
    } else {
    do something different ;
    }

    So in your case you want to write:

    if ( get_group(‘testimonials’,TRUE) ) {

    I hope this helps.

    try this code snippet if the solution above not working:

    <?php $myEvent = get_group('download');
    if($myEvent){ foreach($myEvent as $event){ ?>
    <div class="pdf-download"><a href="<?php echo $event['download_pdf_link'][1]; ?>">
    <?php echo $event['download_pdf_text'][1]; ?></a></div>
    <?php }} ?>

    I’ve got a similar problem. I can’t create a condition that verify if a field (of group, or single or whatelse) is empty. The first snippet post here doesn’t work. The second one doesn’t solve the proble cause it print the “<div>” into the foreach. I need div out of foreach and content inside it.

    I’m no PHP programmer, but after trial an error, this seems to work in my situation. I hope someone will provide a professional solution as this seems too important to ignore.

    We are declaring the group does exist. If the field does not exist within all of our groups, then we want to leave out the field entirely, including its html tag.

    <?php $myEvent = get_group('Faves');
    foreach($myEvent as $event) { ?>
    <?php if($event['fave_title'][1]){ echo '<h2>' . $event['fave_title'][1] . '</h2>'; } ?>
    <?php if($event['fave_summary'][1]){ echo '<div class="summary">' . $event['fave_summary'][1] . '</div>'; } ?>
    <?php } ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Magic Fields] – If Field Is Empty – Don’t Show It!’ is closed to new replies.