Viewing 3 reply threads
  • Author
    Posts
    • #8714

      I’m attempting to configure a setting that controls which post types are registered. I’ve pretty much got the settings page where I need it, but I’m having trouble getting which values are checked. The field group is as follows

      piklist('field', array(
      	'type' => 'group'
      	,'field' => 'cpt_list'
      	,'label' => __('Activate Features', 'checosystem')
      	,'list' => false
      	,'fields' => array(
      		array(
      		'type' => 'checkbox'
      		,'field' => 'common_features'
      		,'label' => __('Common Features', 'checosystem')
      		,'label_position' => 'before'
      		,'value' => 'third'
      		,'choices' => array(
      			'cause_issue' => 'Cause & Issue Management'
      			,'team_manager' => 'Team Member Management'
      		)
      		,'columns' => 2
      		)
      	,array(
      		'type' => 'checkbox'
      		,'field' => 'community_engagement'
      		,'label' => __('Community Engagement', 'checosystem')
      		,'label_position' => 'before'
      		,'value' => 'second'
      		,'choices' => array(
      			'volunteer_management' => 'Volunteer Management'
      			)
      		,'columns' => 2
      		)
      	,array(
      		'type' => 'checkbox'
      		,'field' => 'grassroots_campaigns'
      		,'label' => __('Grassroots Advocacy', 'checosystem')
      		,'label_position' => 'before'
      		,'value' => 'second'
      		,'choices' => array(
      			'campaign_management' => 'Campaign Management'
      			)
      		,'columns' => 2
      		)
      	)
      ));

      I’d like to get the checked values to evaluate which options are check prior to registering the associated post types. For instance:

      
      $theme_options = get_option('my_theme_settings');
      
        $text_field = $theme_options['cpt_list'];
      
        if 'cause_management' {
      // do this
      }

      My experience with PHP is limited, but I’ve tried to get the value of the nested (correct term?) array to no avail. I found one possible example in the demo and documentation but it seems to require a postid. Any help would be much appreciated.

    • #8715
      Steve
      Keymaster

      WordPress saves settings in an array. And when you set a field group in Piklist, those fields are saved in an array… so you’re saving a multidimensional array. Which is perfectly legit, but a little more difficult to get data out of.

      You have two choices:
      1) Use this to get options from your current field: $text_field = $theme_options['cpt_list']['common_features'];
      2) Or get rid of ,'field' => 'cpt_list', which now saves all your settings in a standard array. There are certainly cases where you want to store data multidimensionally, but based on the field you submitted it doesn’t look like you need it. You can then use: $text_field = $theme_options['common_features'];

      Either way is perfectly acceptable.

    • #8717

      Again, thanks! It’s becoming apparent that Piklist opens up a whole new world of possibilities for even those who aren’t developers.

    • #8719
      Steve
      Keymaster

      Glad you’re enjoying using Piklist. One thing Kevin and I made sure of was that Piklist did everything the WordPress way, and also saved data normally. Usually, any tutorial you find on the web, on getting options, will work. It doesn’t have to be a Piklist specific tutorial.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.