Building Select parameter with dynamic content

Hi, i’m trying build a select box as a parameter in a component using dynamic content. I have made a custom dynamic content variable coming from php and I can get a json string or array of the data i want but i can’t get it to work in a dropdown in the parameter. Is this something that can’t be done? or is it just very difficult and I’m missing a piece?

Hello @tonalqualityx,

Thanks for writing in! We would love to check your page set up. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
– Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

image

Best Regards.

Hi @ruenel , i’ve made the secure note. I hope that’s the info you needed. I created a staging environment for this so any changes we make wont effect the live site.

So it does work a bit differently then what you are doing here. This hasn’t come up before so I’ll have to create some docs for you as we solve your request, and this API is a bit new in our system.

See the Dynamic Options section in our docs. When you register your Dynamic Option from that guide, let’s say you named it people_test, you’ll reference it in your parameter via dynamic:people_test where your options are placed in. The way you are formatting the choices data is ready to go from what I saw.

Let us know if this helps and have a great weekend.

{
  "people" : {
    "label" : "People",
    "type" : "select",
    "initial" : "",
    "options" :  "dynamic:people_test"
    
  }
}

It’s saying cs_dynamic_content_register_dynamic_option() call to undefined function.
Here is my edited code.

cs_dynamic_content_register_dynamic_option("people", [
    'key' => "people",
    'type' => "select",
    'label' => __("People", CS_LOCALIZE),
    'options' => [
      'choices' => "dynamic:people",
      'placeholder' => __("Select director", CS_LOCALIZE),
    ],
  
    // Product graber to select
    'filter' => function() {
      // Product choices setup
      $out = [
        [
          'value' => "",
          'label' => "Current director",
        ],
      ];
  

      $array = json_decode(get_option('ind_speakers_list'), true);
  
 
      foreach ($array as $value) {
        $out[] = [
            "value" => $value['id'],
            "label" => $value['name']
        ];
      }

      return $out;
    }
]);

Do you see anything wrong with it? or do i need to enable something? I did enable dynamic content in the settings of theme options but i think that’s enabled by default now. Also i just updated pro to v6.4.21. Any help would be greatly appreciated. thanks.

Wrap your code in the following action and you should be good. Let me know if this helps. Have a great weekend.

add_action('cs_dynamic_content_register', function() {
  // Dynamic options register code
});
1 Like

Thank you! yes it works prefectly.

1 Like

Music to my ears.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.