[Resolved] Multiple Outcomes for a Custom Field

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Multiple Outcomes for a Custom Field

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19738
    Gary
    Participant

    If there can be more than one outcome in a custom field, how do I echo them?

    I have the following code:

    add_action( 'wpsp_after_title', function() {
        $meta = get_post_meta( get_the_ID(), 'geodir_dining_options', true );
    
        if ( $meta ) {
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_equal" search="Dine-In" badge="Dine-In" bg_color="#1ca800" txt_color="#ffffff"]' );
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_equal" search="Take-Away" badge="Take-Away" bg_color="#7ccc66" txt_color="#000000"]' );
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_equal" search="Delivery" badge="Delivery" bg_color="#000000" txt_color="#ffffff"]' );
    		
    		    }
    } ); 

    If there is only one outcome (i.e. dine-in only), there is output. But if there are two or more (dine-in, take-away, delivery), nothing is outputted.

    #19784
    Tom
    Keymaster

    Hi there,

    That code should output three shortcodes if the post meta you’re checking exists. What those shortcodes output depends on the code behind the shortcodes themselves.

    #19819
    Gary
    Participant

    Thanks Tom. My bad. I changed condition=”equals” to condition=”is_contains” and it all worked. I am not sure why, but anyway it’s all good now. Thanks again. Gary

    add_action( 'wpsp_after_title', function() {
        $meta = get_post_meta( get_the_ID(), 'geodir_dining_options', true );
    
        if ( $meta ) {
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_contains" search="Dine-In" badge="Dine-In" bg_color="#7ccc66" txt_color="#000000"]' );
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_contains" search="Take-Away" badge="Take-Away" bg_color="#1ca800" txt_color="#ffffff"]' );
    		echo do_shortcode( '[gd_post_badge key="dining_options" condition="is_contains" search="Delivery" badge="Delivery" bg_color="#000000" txt_color="#ffffff"]' );
    				    }
    } );
    #19925
    Tom
    Keymaster

    Glad you got it sorted! 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.