custompress custom field IF !empty

I want to display four custom fields, if they have a value set in the back. I need to make an IF statement to check to see if a variable is empty or not, but variables arn't used with this plugin, shortcodes are... So how do I see what variable is associated with the shortcode.

Like if (!empty($facebook)) { customfieldshortcode}

The reason for this, is each shortcode outputs a url, that is in a anchor tag with a img. I dont want the img to show up if there is no value in the input field (shortcode).

<?php

/** Replace the standard loop with our custom loop */
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'child_do_custom_loop' );

function child_do_custom_loop() {

if(have_posts()) :
while(have_posts()) :
the_post();
?>

<div class="agent">
<?php if ( has_post_thumbnail() ){ ?>

<div class="agent-image"> <?php the_post_thumbnail(); ?> </div>

<?php } else { ?>

<div class="agent-image">

<img src="http://pensacolamainstreet.com/msp/wp-content/uploads/sites/4/2013/09/Main-Street-Max.jpg" />

</div>

<?php } ?>

<div class="agent-title">

<h2> <?php the_title() ?> </h2>

</div>

<div class="agent-social">

I have four custom fields, facebook, linkedin, twitter, and Google+. I want to display each one here, IF it has a value.

</div>

</div>

<?php
endwhile;
else :
?>

Oops, there are no posts.

<?php
endif;

}

  • Alexander
    • DEV MAN’s Mascot

    Hi @JosephLee1179,

    For something very simple, you could use this:

    echo do_shortcode('[custom_fields_block]');

    That would render out any custom fields that are already set. You can also do something like this to retrieve the data directly:

    $data = get_post_meta( get_the_ID(), $field_id, true );
    if($data) {
    //do something
    }

    For the second parameter that I've marked as $field_id, you need to pass the ID of the custom field, similar to how you would use it in the shortcode.

    Let me know if you need any other assistance here!

    Best regards,

  • JosephLee1179
    • The Incredible Code Injector

    Excellent support, that is exactly what I needed. Thank you Alex.

    Alex, does wpmu still reward people for assisting in the forums? I'm thinking about camping the plugin forums I know/use. I need to become a lifetime member, as my subscription is coming up in a few months.

    I can help with tons of plugins! :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.