Support

Account

Home Forums General Issues Display selected value in Php

Solving

Display selected value in Php

  • Hi,

    I created a custom field which is a selectbox (multiselect in admin). On the frontend i made a dropdown list where the options selected in the backend are displayed.

    My question: an user can select in the dropdown 1 value.. but how do i retrieve the choisen value in other PHP template files?

    Thank you guys in advance

  • If I understand your question correctly, you want to retrieve the chosen values for usage in your template files.

    Here’s information on how to get values from other posts:
    https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

  • I can make the possible values displayed one a page. But not the selected one.

    The code i’m using so far:

    <?php
    $beschikbaar = get_field('beschikbaar');
    ?>
    <select name="beschikbaar" id="beschikbaar">
      <option>Maak je keuze</option>
      <?php
        foreach($beschikbaar as $beschikbaar) { ?>
          <option value="<?php echo $beschikbaar; ?>"><?php echo $beschikbaar; ?></option>
      <?php
        } ?>
    </select> 
  • I’m not sure if I understand you correctly. I created a checkbox field on the backend and adding your code to a single.php file. When selecting a value in the backend, it correctly shows my selected value.

    Selected value in backend

  • Yes this goes well. My question is: how do I get the value as selected in the frontend (test1 in your example) retreived in another page.

  • Hi lepel

    You should add the post ID in the get_field function: https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/

    
    <?php 
    $post_ID = 5; // this is the ID of the page which contains the values selected
    $beschikbaar = get_field('beschikbaar', $post_ID);
    
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.