Viewing 3 reply threads
  • Author
    Posts
    • #3856
      justin
      Member

      I am trying to display a group I created in piklist on the front end, and I keep getting an error that my output is not in an array.

      Here is the group I created:

      
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'user_jobs_group'
          ,'add_more' => true
          ,'label' => __('Jobs')
      	,'columns' => 12
          ,'description' => 'Add each job and history.'
          ,'fields' => array(
      		array(
              'type' => 'select'
              ,'field' => 'user_job'
              ,'label' => 'Job'
              ,'columns' => 4
              ,'choices' => piklist(
      						get_posts(
      							array(
      								'post_type' => 'post_jobs'
      								,'orderby' => 'title'
      								,'order' => 'asc'
      								,'posts_per_page' => -1
      							)
      							,'objects'
      						)
      						,array(
      							'ID'
      							,'post_title'
      						)
      						)
            )
      	  ,array(
      	  'type' => 'datepicker'
      	 ,'field' => 'user_job_start'
      	 ,'label' => 'Start'
      	 ,'columns' => 3
      	,'options' => array(
      	   'dateFormat' => 'yy-mm-dd'
      	   ,'firstDay' => '0'
      	)
          )
      	,array(
              'type' => 'radio'
      		,'field' => 'user_job_current'
      		,'label' => 'Current?'
      		,'columns' => 2
      		,'choices' => array(
      		  'job_current' => 'Current'
      		  ,'job_old' => 'Past'
      )
            )
      	,array(
      	  'type' => 'datepicker'
      	 ,'field' => 'user_job_end'
      	 ,'label' => 'End'
      	 ,'columns' => 3
      	 ,'conditions' => array(
         array(
          'field' => 'user_job_current'
          ,'value' => 'job_current'
         )
       )
      	,'options' => array(
      	   'dateFormat' => 'yy-mm-dd' 
      	   ,'firstDay' => '0'
      	)
          )
      	)
      
        ));
      

      Here is the array output:

      
      Array (
       [0] => Array (
       [user_job] => Array ( [0] => 1486  [1] => 1128  ) 
       [user_job_start] => Array ( [0] => 2015-06-11 [1] => 2014-09-16 ) 
       [user_job_current] => Array ( [0] => Array ( [0] => job_current ) [1] => Array ( [0] => job_current ) ) 
       [user_job_end] => Array ( [0] => [1] => 2015-06-11 ) ) )
      

      Here is my Template:

      
      <?php 
      echo $data['user_job']; 
      echo $data['user_job_start']; 
      echo $data['user_job_current']; 
      echo $data['user_job_end']; 
      ?>
      

      Here are the errors

      
      Warning: array_keys() expects parameter 1 to be array, string given in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-content/plugins/piklist/includes/class-piklist.php on line 1336
      
      Warning: Invalid argument supplied for foreach() in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-content/plugins/piklist/includes/class-piklist.php on line 346
      
      Warning: Invalid argument supplied for foreach() in /home/micdri10/EXTREMESOUTHAMERICA.COM/wp-content/plugins/piklist/includes/class-piklist.php on line 354
      
    • #3857
      Steve
      Keymaster

      @justin

      Since you are using an add-more, $data['user_job'] is also an array.

      Try this:

      $user_job = $data['user_job'];
      
      foreach ($user_job as $job => $value)
      {
        echo $value;
      }
      
    • #3858
      justin
      Member

      Ok, So i figured out some things. If I change the variable to start in the first array [0] then I can use the template correctly.

      Here is the front end code:

      
      $user_jobs = get_user_meta($curauth->ID, 'user_jobs_group', false);
      piklist('template' . '/user_jobs_template', array('data' => $user_jobs[0], 'loop' => 'data'));
      

      Here is the template file:

      
      <?php 
      echo $data['user_job']; 
      echo $data['user_job_start']; 
      echo $data['user_job_current'][0]; 
      echo $data['user_job_end']; 
      ?>
      

      Thanks for the help.

    • #3859
      Steve
      Keymaster

      @justin– Great! Let us know if you need anything else. Closing ticket.

Viewing 3 reply threads
  • The topic ‘template error not array’ is closed to new replies.