Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

why is this returning an array?

Featured Replies

I've been tearing my hair out over this since this morning and I just can't work it out. The item in the select box should return a list of teams- which it does, but when I check the value returned it is : a:1:{i:0;s:3:"207";}

 

I would be eternally grateful for some help with this or even for just a hint.

 

I know this is Wordpress but I thought it was more of a php question so I posted it here. Feel free to move it if need be.

<?php

//_______________________________MATCH REPORT FIELDS_____________________________

// Field Array
$prefix = 'report_';
$report_custom_meta_fields = array(

	array(
		'label' => 'Match Date',
		'desc' => 'Choose match date',
		'id' => $prefix.'date',
		'type' => 'date'
	),
	array(
		'label' => 'Select Home Team',
		'desc' => 'Select home team from list',
		'id'    =>  $prefix.'home-select',
		'type' => 'post_list',
		'post_type' => array('team_page')
	),
	array(
		'label' => 'Select Home Score',
		'desc' => 'Select home score',
		'id' => $prefix . 'homescore-select',
		'type' => 'number'
	),
	array(
		'label' => 'Select Away Team',
		'desc' => 'Select away team from list',
		'id' => $prefix.'away-select',
		'type' => 'post_list',
		'post_type' => array('team_page')
	),
	array(
		'label' => 'Select Away Score',
		'desc' => 'Select away team score',
		'id' => $prefix . 'awayscore-select',
		'type' => 'number'
	)
);



$prefix = 'report_';

/**
 *_________________________________MATCH REPORT________________________________*/
 
 
 
$report_box = new custom_add_meta_box( 'match_report', 'Match Report', $report_custom_meta_fields, 'match_report', true );


function report_custom_meta_box_field( $field, $meta = null, $repeatable = null ) {
	if ( ! ( $field || is_array( $field ) ) )
		return;

	// get field data
	$type = isset( $field['type'] ) ? $field['type'] : null;
	$label = isset( $field['label'] ) ? $field['label'] : null;
	$desc = isset( $field['desc'] ) ? '<span class="description">' . $field['desc'] . '</span>' : null;
	$place = isset( $field['place'] ) ? $field['place'] : null;
	$size = isset( $field['size'] ) ? $field['size'] : null;
	$post_type = isset( $field['post_type'] ) ? $field['post_type'] : null;
	$options = isset( $field['options'] ) ? $field['options'] : null;
	$settings = isset( $field['settings'] ) ? $field['settings'] : null;
	$repeatable_fields = isset( $field['repeatable_fields'] ) ? $field['repeatable_fields'] : null;

	// the id and name for each field
	$id = $name = isset( $field['id'] ) ? $field['id'] : null;
	if ( $repeatable ) {
		$name = $repeatable[0] . '[' . $repeatable[1] . '][' . $id .']';
		$id = $repeatable[0] . '_' . $repeatable[1] . '_' . $id;
	}
	switch( $type ) {
		// basic
	case 'text':
	case 'tel':
	case 'email':
	default:
		echo '<input type="' . $type . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="' . esc_attr( $meta ) . '" class="regular-text" size="20" />
<br />' . $desc;
		break;
	case 'url':
		echo '<input type="' . $type . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="' . esc_url( $meta ) . '" class="regular-text" size="30" />
<br />' . $desc;
		break;
	case 'number':
		echo '<input type="' . $type . '" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="' . intval( $meta ) . '" class="regular-text" size="10" />
<br />' . $desc;
		break;

		// select, chosen
	case 'select':
	case 'chosen':
		echo '<select name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '"' , $type == 'chosen' ? ' class="chosen"' : '' , isset( $multiple ) && $multiple == true ? ' multiple="multiple"' : '' , '>
<option value="">Select One</option>'; // Select One
		foreach ( $options as $option )
			echo '<option' . selected( $meta, $option['value'], false ) . ' value="' . $option['value'] . '">' . $option['label'] . '</option>';
		echo '</select><br />' . $desc;
		break;

	case 'post_list':
	
		echo '<select data-placeholder="Select Team" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '"'>';

<option value="">Select Team</option>';  
		$items = get_posts( array (  
			    'post_type' => $field['post_type'],  
			    'posts_per_page' => -1  
			));
		
		foreach ( $items as $item )
			echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->post_title.'</option>';
		$post_type_object = get_post_type_object( $post_type );
		echo '</select>  <span class="description"><a href="' . admin_url( 'edit.php?post_type=' . $post_type . '">Manage ' . $post_type_object->label ) . '</a></span><br />' . $desc;
		break;
		
	case 'post_t':  
			$item = get_posts( array (  
			    'post_type' => $field['post_type'],  
			    'posts_per_page' => -1  
			));  
			
			    echo '<select name="'.$field['id'].'" id="'.$field['id'].'"> 
			            <option value="">Select One</option>'; // Select One  
			        foreach($items as $item) {  
			            echo '<option value="'.$item->ID.'"',$meta == $item->ID ? ' selected="selected"' : '','>'.$item->post_title.'</option>';  
			        } // end foreach  
			    echo '</select><br /><span class="description">'.$field['desc'].'</span>';  
			break;
		
	} //end switch
}

	/**
	 * adds the meta box for every post type in $page
	 */
	function add_box() {
		foreach ( $this->page as $page ) {
			add_meta_box( $this->id, $this->title, array( $this, 'meta_box_callback' ), $page, 'normal', 'high' );
		}
	}

	/**
	 * outputs the meta box
	 */
	function meta_box_callback() {
		// Use nonce for verification
		wp_nonce_field( 'custom_meta_box_nonce_action', 'custom_meta_box_nonce_field' );

		// Begin the field table and loop
		echo '<table class="form-table meta_box">';
		foreach ( $this->fields as $field) {
			if ( $field['type'] == 'section' ) {
				echo '<tr>
<td colspan="2">
<h2>' . $field['label'] . '</h2>
</td>
</tr>';
			}
			else {
				echo '<tr>
<th style="width:20%"><label for="' . $field['id'] . '">' . $field['label'] . '</label></th>
<td>';

				$meta = get_post_meta( get_the_ID(), $field['id'], true);
				echo goal_info_meta_box_field( $field, $meta );

				echo '<td>
</tr>';
			}
		} // end foreach
		echo '</table>'; // end table
	}

	/**
	 * saves the captured data
	 */
	function save_box( $post_id ) {
		$post_type = get_post_type();

		// verify nonce
		if ( ! isset( $_POST['custom_meta_box_nonce_field'] ) )
			return $post_id;
		if ( ! ( in_array( $post_type, $this->page ) || wp_verify_nonce( $_POST['custom_meta_box_nonce_field'], 'custom_meta_box_nonce_action' ) ) )
			return $post_id;
		// check autosave
		if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
			return $post_id;
		// check permissions
		if ( ! current_user_can( 'edit_page', $post_id ) )
			return $post_id;

		// loop through fields and save the data
		foreach ( $this->fields as $field ) {
			if( $field['type'] == 'section' ) {
				$sanitizer = null;
				continue;
			}
			if( in_array( $field['type'], array( 'tax_select', 'tax_checkboxes' ) ) ) {
				// save taxonomies
				if ( isset( $_POST[$field['id']] ) ) {
					$term = $_POST[$field['id']];
					wp_set_object_terms( $post_id, $term, $field['id'] );
				}
			}
			else {
				// save the rest
				$new = false;
				$old = get_post_meta( $post_id, $field['id'], true );
				if ( isset( $_POST[$field['id']] ) )
					$new = $_POST[$field['id']];
				if ( isset( $new ) && '' == $new && $old ) {
					delete_post_meta( $post_id, $field['id'], $old );
				} elseif ( isset( $new ) && $new != $old ) {
					$sanitizer = isset( $field['sanitizer'] ) ? $field['sanitizer'] : 'sanitize_text_field';
					if ( is_array( $new ) )
						$new = meta_box_array_map_r( 'meta_box_sanitize', $new, $sanitizer );
					else
						$new = meta_box_sanitize( $new, $sanitizer );
					update_post_meta( $post_id, $field['id'], $new );
				}
			}
		} // end foreach
	}

}

 

 

 

  • Author

:fool: Actually, it was because I used the same variable $meta further down in the code and defined it as an array :blush1:

 

Thank you to whoever tried to help.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.