• So I’m looking to utilize the custom field entries in a bit of an interesting way but I am worthless at php.

    What I’m wanting to do is create a custom field, then recognize what it is and print something standard if it is a certain entry.

    So example: I have a custom field called “disclaimer”. I have a variety of different disclaimers depending on which one of my authors (because they come from different companies). So instead of having to copy and paste an entire disclaimer into the custom entry field, I’m trying to make it I just type “1” for disclaimer 1. And when the php sees “1” as the content for custom field “disclaimer” 40 lines of legal babble vomit out.

    Ideas?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Rocky,

    Great way to streamline your workflow. I would create a function in functions.php to handle this. You could then add the function name to your templates where you want the disclaimer to show if there is one.

    function rct_disclaimers() {
        $disclaimer = get_post_meta( $post->ID, 'disclaimer', true);
        if ( empty( $disclaimer )
                return;   //breaks out of function if no disclaimer set.
    
        if ( 'disclaimer-1' == $disclaimer ) {
    
           ///// echo out your disclaimer 
    
         } elseif ( 'dislcaimer-2 == $disclaimer ) {
    
            //// echo out disclaimer 
    
         }

    You get the idea. Just put <?php rat_disclaimers(); ?> in single.php. Also I would use disclaimer-2 etc… instead of just the single number for meta field.

    If you want the disclaimer to show up at a different location depending on the page or disclaimer number, use a similar technique to that suggested by Chris, but use a shortcode instead of a function in the template.

    Thread Starter Rocky.Colt.TumTum

    (@rockycolttumtum)

    Wow. Thanks guys. This looks great.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Field If/Thens’ is closed to new replies.