Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select field type not outputting choices #151

Open
IllustrateNathan opened this issue May 25, 2022 · 1 comment
Open

Select field type not outputting choices #151

IllustrateNathan opened this issue May 25, 2022 · 1 comment

Comments

@IllustrateNathan
Copy link

IllustrateNathan commented May 25, 2022

Hello,

In my field builder for my select field I am using a PHP variable which stores an associative array of block ID's and Names which the user is able to select from, this was working fine with WP V5.9, ACF V5.11.4 and the latest version of StoutLogic ACF Builder but doesn't output any options when updating ACF to any V5.12.*.

Please see below a var_dump of my field->build

array(4) {
  ["key"]=>
  string(30) "group_anchor_navigation_fields"
  ["title"]=>
  string(24) "Anchor Navigation Fields"
  ["fields"]=>
  array(3) {
    [0]=>
    array(5) {
      ["type"]=>
      string(7) "message"
      ["name"]=>
      string(25) "block_title_label_message"
      ["label"]=>
      string(30) "ANCHOR NAVIGATION BLOCK FIELDS"
      ["key"]=>
      string(56) "field_anchor_navigation_fields_block_title_label_message"
      ["message"]=>
      NULL
    }
    [1]=>
    array(8) {
      ["type"]=>
      string(8) "repeater"
      ["name"]=>
      string(20) "tabbed_content_links"
      ["label"]=>
      string(5) "Links"
      ["key"]=>
      string(51) "field_anchor_navigation_fields_tabbed_content_links"
      ["instructions"]=>
      string(385) "Important: This block must be used towards the top of the page, above any content you wish to link to. You should only include this block on a page once. 
Hint: if there are no options, try saving the page and reloading it, the select field should then populate with available blocks. 
Maximum 10 items to avoid display issues. 
If you leave this empty, the nav will not show."
      ["button_label"]=>
      string(8) "Add Link"
      ["max"]=>
      int(10)
      ["sub_fields"]=>
      array(2) {
        [0]=>
        array(16) {
          ["choices"]=>
          array(8) {
            ["block_620d1664dfbea"]=>
            string(23) "Image Or Video And Text"
            ["block_620d1b8cdfbeb"]=>
            string(9) "Card Grid"
            ["block_620d1c32dfbf0"]=>
            string(14) "Tabbed Content"
            ["block_620d1fd6dfbf9"]=>
            string(9) "Card Grid"
            ["block_620d23dbdfc07"]=>
            string(15) "Icon Text Cards"
            ["block_6218df7efbd59"]=>
            string(9) "Team Feed"
            ["block_620d20d9dfc02"]=>
            string(11) "Testimonial"
            ["block_6218e015fbd61"]=>
            string(13) "Insights Feed"
          }
          ["type"]=>
          string(6) "select"
          ["name"]=>
          string(10) "link_block"
          ["label"]=>
          string(5) "Block"
          ["key"]=>
          string(62) "field_anchor_navigation_fields_tabbed_content_links_link_block"
          ["instructions"]=>
          string(24) "Select block to link to."
          ["required"]=>
          int(1)
          ["conditional_logic"]=>
          int(0)
          ["wrapper"]=>
          array(1) {
            ["width"]=>
            string(2) "50"
          }
          ["default_value"]=>
          string(19) "block_620d1664dfbea"
          ["allow_null"]=>
          int(0)
          ["multiple"]=>
          int(0)
          ["ui"]=>
          int(0)
          ["ajax"]=>
          int(0)
          ["return_format"]=>
          string(3) "key"
          ["placeholder"]=>
          string(12) "Select Block"
        }
        [1]=>
        array(5) {
          ["type"]=>
          string(4) "text"
          ["name"]=>
          string(9) "link_text"
          ["label"]=>
          string(9) "Link Text"
          ["key"]=>
          string(61) "field_anchor_navigation_fields_tabbed_content_links_link_text"
          ["required"]=>
          bool(true)
        }
      }
    }
    [2]=>
    array(6) {
      ["choices"]=>
      array(4) {
        [""]=>
        string(0) ""
        ["red"]=>
        string(3) "Red"
        ["blue"]=>
        string(4) "Blue"
        ["teal"]=>
        string(4) "Teal"
      }
      ["type"]=>
      string(6) "select"
      ["name"]=>
      string(14) "colour_overide"
      ["label"]=>
      string(16) "Override Colour?"
      ["key"]=>
      string(45) "field_anchor_navigation_fields_colour_overide"
      ["default_value"]=>
      array(1) {
        [0]=>
        string(0) ""
      }
    }
  }
  ["location"]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      array(3) {
        ["param"]=>
        string(5) "block"
        ["operator"]=>
        string(2) "=="
        ["value"]=>
        string(21) "acf/anchor-navigation"
      }
    }
  }
}

Any help or suggestions would be appreciated.

Regards

@simonillustrate
Copy link

simonillustrate commented Aug 23, 2022

To follow up - we had to investigate this ourselves and turns out the latest ACF runs block fields through admin ajax and as such $_GET or $post are not available. So the get the post id we ended up doing:

$url = wp_get_referer();
// Now get the components.
$url_components = wp_parse_url( $url );
// Now  get the query from the components.
parse_str( $url_components['query'], $params );
// If we have a post value, check for blocks.
if ( isset( $params['post'] ) && is_admin() ) :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants