0

I have an advanced custom fields field called job_type. It is a select type field so it has a number of values in the field like Contract, Freelance, Permanent etc. So I list all the jobs on a page and now I want to have exposed filters on the left where a user can choose to filter the jobs based on various fields. So for example if he chooses Freelance the page should (with ajax) show only the jobs that are of type 'Freelance'

How do I get the values from the field into a select list please?

0

If you mean an ACF select field:

<?php
$field = get_field_object('my_select');
var_dump( $field['choices'] );
?>

More info here https://www.advancedcustomfields.com/resources/get_field_object/

3
  • returns NULL and there are for sure values for the field. I have added the values Part-time Freelance Contract Full time
    – calvincani
    Jul 14 '20 at 9:50
  • im assuming you updated the code above with the actual id of your field - instead of 'my_select' ? Jul 15 '20 at 6:05
  • Yes I named it to the name of the field as it is in the ACF field group. So not the name of the field group but the actual name of the field, job_type. <div class="jobTypeSelect"> <?php $field = get_field_object('job_type'); var_dump( $field['choices'] ); ?> </div>
    – calvincani
    Jul 15 '20 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.