CustomPress 'if' custom field is ticket 'then'

Hi there. I am using Custompress to add a custom field to my regular WP posts. The field is actually a check box, and the idea is that if the checkbox is ticked, then it does not show the featured image in the actual post (as the post is going to show an infographic so 2 images is overkill).

So I have the code below which is meant to add 'display:none;' to the featured image 'div' if the custom field box is ticked:

<div class="featuredimage" <?php if( get_post_meta($post->ID, '_ct_text_513016b86c9b7', true) ) { ?> style="display:none;" <?php } ?>>

I am fairly sure this was working the other day, but it doesn't seem to be now working now and 'display:none;' is always the case. Do you know if there is anything wrong with the snippet?

Many thanks,
Craig

  • Vaughan
    • Support/SLS MockingJay

    hi @ffdltd

    thanks for posting.

    the last attribute can either be true or false. If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields.

    which in your case above, no matter what the if() is gonna be true.

    can you try

    <div class="featuredimage" <?php $custom = get_post_meta($post->ID, '_ct_text_513016b86c9b7', true);
    
     if(isset($custom) && $custom !== '') { ?> style="display:none;"<?php } ?>>

    if that fails, try echo $custom; to see what $custom is set, it might narrow down whats happening.

    hope this helps.

  • ffdltd
    • Design Lord, Child of Thor

    Hi there. Thanks very much for your response.

    I have tried with no luck. When I echo the $custom is displays either '-1' (if unchecked) and 'Array' (if checked).

    I just realised I did try to see tis output before, BUT I put the code inside the 'IF' so it was never going to show haha.

    So with this, how would I add the output from a checked box to the above code?

    Thanks again!! :slight_smile:

  • Vaughan
    • Support/SLS MockingJay

    hiya

    sorry for the delay.

    this may not be perfect solution, but i think will work.

    <div class="featuredimage" <?php $custom = get_post_meta($post->ID, '_ct_text_513016b86c9b7', true);
    
     if((isset($custom) && $custom >= 1) || is_array($custom)) { ?> style="display:none;"<?php } ?>>

    hope this helps.

    thanks.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.