问题
it's my first question here. My PHP is sort of ok and I duplicate/modify code to get what I want usually but I'm very lost here and not sure where to get the info I need
MAIN ISSUE I don't know what to call to get things inside ARRAY
What I need is inside that Array of Extras. I've duplicated & modified everything I can to get these values but can't seem to figure it out. Any help is really appreciated.
The registration, milage, condition shown is the output of $autoshowroom_portfolio_specifications_arr
Things I've tried (below but commented/removed most of it after) and what it's calling what you see in image above
The main line here is <?php echo balanceTags(tz_autoshowroom_get_vehicle_specs(get_the_ID(), 'all')); ?>
which is calling all values from Registration Date - 100 HP and has the inner Array I need
<div class="vehicle-box">
<h3 class="widget-title"><span><?php esc_html_e('Specifications', 'autoshowroom'); ?></span>
</h3>
<?php if ($autoshowroom_detail_model || $autoshowroom_detail_make == 'yes') : ?>
<div class="pcd-specs">
<?php if ($autoshowroom_detail_make == 'yes') { ?>
<div>
<label><?php esc_html_e('Make', 'autoshowroom'); ?></label>
<span>
<?php $autoshowroom_vehicle_make = wp_get_post_terms(get_the_ID(), 'make');
foreach ($autoshowroom_vehicle_make as $make) {
$ve_make = $make->slug;
echo esc_attr($make->name);
}
?>
</span>
</div>
<?php } ?>
<?php if ($autoshowroom_detail_model == 'yes') { ?>
<div>
<label><?php esc_html_e('Model', 'autoshowroom'); ?></label>
<span>
<?php $autoshowroom_vehicle_make = wp_get_post_terms(get_the_ID(), 'model');
foreach ($autoshowroom_vehicle_make as $make) {
echo esc_attr($make->name);
}
?>
</span>
</div>
<?php } ?>
<div class="clr"></div>
</div>
<?php endif; ?>
<?php
echo implode( ", ", balanceTags(tz_autoshowroom_get_vehicle_specs(get_the_ID(), 'all')));
echo '<br /><br />';
echo $color_choices['inactiveTags'];
echo $autoshowroom_detail_model; // yes
print_r($car_extras);
echo '<br /><h1>neww</h1>';
echo $autoshowroom_detail_extras;
echo balanceTags(tz_autoshowroom_get_vehicle_specs(get_the_ID(), $autoshowroom_portfolio_specifications_arr));
echo '<br /><h1>===</h1>';
echo $autoshowroom_detail_extras;
echo '<br /><h1>=5==</h1>';
echo implode(",",$autoshowroom_portfolio_specifications_values);
echo implode( ", ", $autoshowroom_portfolio_specifications_arr );
echo '<br /><p>===</p>';
// actual data
echo implode( ", ", $car_extras );
print_r($car_extras);
echo $autoshowroom_detail_extras;
echo implode( ", ", balanceTags(tz_autoshowroom_get_vehicle_specs(get_the_ID(), 'autoshowroom_detail_extras')));
echo implode( ", ", $autoshowroom_TZVehicle_specs );
echo implode( ", ", $autoshowroom_portfolio_specifications_arr );
echo $autoshowroom_detail_model;
echo $autoshowroom_portfolio_specifications_arr;
echo tz_autoshowroom_get_vehicle_specs(get_the_ID(),$autoshowroom_specifications_arr);
// show extras after make model
echo balanceTags(tz_autoshowroom_filter_vehicle_price(get_the_ID(),$showmsrp));
echo balanceTags($autoshowroom_text_title);
echo balanceTags( $name );
?>
<?php echo balanceTags(tz_autoshowroom_get_vehicle_specs(get_the_ID(), 'all')); ?>
<?php
if (class_exists('Comment_Rating_Output')):
$average_rating = get_post_meta(get_the_ID(), 'tz-average-rating', true);
if (empty($average_rating)) {
$average_rating = 0;
}
echo '<div class="tz-average-rating"><div class="tz-rating tz-rating-' . esc_attr($average_rating) . '"></div></div>';
endif;
?>
</div>
Using this echo implode( ", ", $autoshowroom_portfolio_specifications_arr );
I'm able to get the actual STRING values from wordpress db which shows the registration, milage, condition
So here's what I have for some of the code to give an idea from single-vehicle.php which is what I use to show front end user results (not sure if it's better to just add all three files needed for this here) $autoshowroom_portfolio_specifications_arr = ot_get_option('autoshowroom_TZVehicle_specs');
and below in theme-options.php (notice the choices)
array(
'id' => 'autoshowroom_TZVehicle_specs',
'label' => esc_html__('Choose Specifications to display', 'autoshowroom'),
'desc' => esc_html__('Specifications has checked will display on inventory page(You should choose max is 3 item to nice view)', 'autoshowroom'),
'std' => '',
'type' => 'checkbox',
'section' => 'TZVehicle',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'min_max_step' => '',
'class' => '',
'condition' => '',
'operator' => 'and',
'choices' =>
tz_autoshowroom_get_fields()
),
and the function is
function tz_autoshowroom_get_fields() {
global $car_dealer;
if (is_plugin_active('progression-car-dealer-master/progression-car-dealer.php')) {
$fields = $car_dealer->fields->get_registered_fields('specs');
$auto_fields = array();
if ($fields != null) {
foreach ($fields as $i => $field) {
$auto_fields[$i]['value'] = $field['name'];
$auto_fields[$i]['label'] = $field['label'];
$auto_fields[$i]['src'] = '';
}
} else {
$auto_fields[0]['value'] = 'none';
$auto_fields[0]['label'] = 'no Specifications ';
$auto_fields[0]['src'] = '';
}
return $auto_fields;
}
}
which uses the following to show vehicle options in multiple arrays from theme options file
My duplicate/modified codes below in theme-options.php (again notice the choices)
array(
'id' => 'autoshowroom_Detail_show_extras',
'label' => esc_html__('Show Extras', 'autoshowroom'),
'desc' => '',
'sdt' => 'yes',
'type' => 'select',
'section' => 'TZVehicleDetail',
// 'section' => 'TZVehicle',
'choices' => array(
array(
'value' => 'yes',
'label' => esc_html__('Show', 'autoshowroom'),
),
array(
'value' => 'no',
'label' => esc_html__('Hide', 'autoshowroom'),
)
)
),
in class-car-dealer-fields.php is where I have the actual values of these options/extras set and I've duplicated color_choices as the example to get the following inside public function __construct()
$car_extras = array_unique( array_merge( array (
__( 'Auxiliary heating', 'progression-car-dealer' ),
__( 'ABS', 'progression-car-dealer' ),
__( 'Central locking', 'progression-car-dealer' ),
__( 'Power Assisted Steering', 'progression-car-dealer' ),
__( 'Cruise control', 'progression-car-dealer' ),
__( 'Immobilizer', 'progression-car-dealer' ),
__( 'Warranty', 'progression-car-dealer' ),
__( 'Electric windows', 'progression-car-dealer' ),
__( 'Financing', 'progression-car-dealer' ),
__( 'Another', 'progression-car-dealer' ),
__( 'Last', 'progression-car-dealer' ),
), $this->get_meta_values( 'extras', 'vehicle' ) ));
$car_extras = array_combine( $car_extras, $car_extras);
and here are some other settings also inside the public function __construct() {
but inside this array $this->built_in = array(
'milage' => array(
'label' => __( 'Mileage', 'progression-car-dealer' ),
'name' => 'milage',
'type' => 'number',
'instructions' => __( 'The number of miles travelled or covered', 'progression-car-dealer' ),
'default_value' => '',
'placeholder' => __( 'e.g. 70000', 'progression-car-dealer' ),
'prepend' => '',
'append' => get_option( 'options_pcd_milage_unit', 'mi' ),
'sort' => 20
),
'condition' => array(
'label' => __( 'Condition', 'progression-car-dealer' ),
'name' => 'condition',
'instructions' => '',
'type' => 'radio',
'choices' => array(
'new' => __( 'New', 'progression-car-dealer' ),
'used' => __( 'Used', 'progression-car-dealer' ),
'preowned' => __( 'Certified Pre-Owned', 'progression-car-dealer' )
),
'default_value' => 'new',
'other_choice' => 0,
'sort' => 30
),
'color' => array(
'label' => __( 'Exterior Color', 'progression-car-dealer' ),
'name' => 'color',
'type' => 'radio',
'choices' => $color_choices,
'other_choice' => 1,
'save_other_choice' => 1,
'default_value' => 'silver',
'layout' => 'horizontal',
'sort' => 40,
),
'interior' => array(
'label' => __( 'Interior Color', 'progression-car-dealer' ),
'name' => 'interior',
'type' => 'radio',
'choices' => $int_color_choices,
'other_choice' => 1,
'save_other_choice' => 1,
'default_value' => 'black',
'layout' => 'vertical',
'sort' => 50,
),
'transmission' => array(
'label' => __( 'Transmission', 'progression-car-dealer' ),
'name' => 'transmission',
'type' => 'radio',
'choices' => array (
'auto' => __( 'Automatic', 'progression-car-dealer' ),
'manual' => __( 'Manual', 'progression-car-dealer' ),
),
'default_value' => '',
'layout' => 'horizontal',
'sort' => 60,
),
'engine' => array (
'label' => __( 'Engine', 'progression-car-dealer' ),
'name' => 'engine',
'instructions' => __( 'The displacement the engine gives in Litres', 'progression-car-dealer' ),
'append' => 'L',
'placeholder' => '4,1',
'sort' => 70,
'min' => 0,
'max' => 10
),
// eddie
// show in car editor specifications tab
'extras' => array(
'label' => __( 'Extras', 'progression-car-dealer' ),
'name' => 'extras',
'type' => 'checkbox',
'choices' => $car_extras,
'other_choice' => 55,
'save_other_choice' => 55,
'default_value' => '',
'layout' => 'horizontal',
'sort' => 95,
),
I also duplicated one of these arrays to get the checkbox typeextras
public function register_field( $args ) {
// ACF requires a unique key per field so lets generate one
$key = md5( serialize( $args ));
if ( empty( $args['type'] )) {
$args['type'] = 'number';
}
$type = $args['type'];
if ( 'taxonomy' == $type ) {
$field = wp_parse_args( $args, array(
'key' => $key,
'label' => '',
'name' => '',
'type' => 'taxonomy',
'instructions' => '',
'taxonomy' => '',
'field_type' => 'select',
'allow_null' => 1,
'load_save_terms' => 1,
'return_format' => 'id',
'multiple' => 0,
'sort' => 0,
'group' => 'overview'
) );
} else if ( 'radio' == $type ) {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'instructions' => '',
'choices' => array(),
'other_choice' => 1,
'save_other_choice' => 1,
'default_value' => '',
'layout' => 'horizontal',
'sort' => 0,
'group' => 'specs'
) );
} else if ( 'checkbox' == $type ) {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'instructions' => '',
'choices' => array(),
'layout' => 'vertical',
'sort' => 0,
'multiple' => 1,
'group' => 'specs'
) );
} else {
$field = wp_parse_args( $args, array (
'key' => $key,
'label' => '',
'name' => '',
'type' => 'number',
'instructions' => '',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => 0,
'max' => '',
'step' => '',
'sort' => 0,
'group' => 'specs'
) );
}
$field = apply_filters( 'pcd/register_field', $field );
$this->fields[$field['name']] = $field;
Finally also in class-car-dealer-fields.php file inside register_field_group(array
there are many arrays of settings for the admin (is where the client would select what extras to show in the front end but this part actually works except for some extra weirdness highlighted in red below at the end which seems to be a string in the db (I removed it from db and it came back after selecting some options and saving.
array (
'label' => __( 'Checkboxes field', 'progression-car-dealer' ),
'name' => 'pcd_checkboxes',
'display' => 'table',
'min' => '',
'max' => '',
'sub_fields' => array (
array (
'key' => 'field_52816dc9ffee11',
'label' => __( 'Checkboxes to Customize', 'progression-car-dealer' ),
'name' => 'pcd_checkboxes',
'type' => 'checkbox',
'instructions' => __( 'Selected fields will be used', 'progression-car-dealer' ),
'choices' => $choices,
'default_value' => '',
'layout' => 'horizontal',
)
),
),
Settings below in WP but this was to mainly get what I need into the WP post page so I don't need to create more
来源:https://stackoverflow.com/questions/64938233/how-to-get-values-only-from-a-php-array-inside-multiple-nested-arrays-without-kn