Support

Account

Home Forums Front-end Issues Select -> Conditional field values stored and are overlapping

Helping

Select -> Conditional field values stored and are overlapping

  • I have a Select field with three options:
    file : File
    page : Page Link
    url : External Link

    When an option is selected the appropriate field is shown (conditional logic: If Select is Equal To “page” -> Show Page Select Field “Page Link”)
    Each field is a different type (file, page link, text) allowing for multiple types of content to be displayed in the template file.

    This is the code I’m using for the template:

    <a href="
          <?php 
    	   if(get_field('push_notification_type') == "url") {
    		?>http://<?php the_field('push_notification_url');
    	   } elseif (get_field('push_notification_type') == "page") {
    		the_field('push_notification_page'); 
    	   } elseif (get_field('push_notification_type') == "file") {
    		the_field('push_notification_file');
    	   } ?>		
    ">Click me</a>

    The desired result would be that IF “url” is chosen on the select field and data has been entered into the field, show “url” in template. Then when updating the page, change the Select value to be “page” and remove the previous value for “url” upon update. What this actually does is show the field value for every option that has been filled out… meaning I cannot Choose “url” fill out the conditional field, update my post, edit the post, Change my Select option to “page”, fill out field, update post. When I do this it retains the previous value for “url”, thus displaying multiple values in my code above (i.e. http://www.website.com/http://localhost/pagelink )

    Is there anyway to clear the conditional field value when a new selection has been made?

  • Hi @YohoGDES

    The select field push_notification_type can only hold 1 value at 1 time, so your above code featuring the if and else statements, should work correctly.

    Only 1 of those statements will be true, and then only 1 of the actions will be run (the_field).

    I can’t explain why you are seeing 2 urls. Perhaps you need to debug the code to make sure the the_field values are correct.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Select -> Conditional field values stored and are overlapping’ is closed to new replies.