Hi,
Here is the code for adding two custom fields, which I inserted in functions.php file
1. Custom select – City (Dropdown, not a ‘required’ field, only one selection allowed)
2. Custom checkbox – Choose Fabric (not ‘required’ field, multiple selection allowed)
add_filter( "adverts_form_load", "my_adverts_form_load" );
function my_adverts_form_load( $form ) {
if( $form["name"] != "advert" ) {
return $form;
}
$form["field"][] = array(
"name" => "my_custom_city",
"type" => "adverts_field_select",
"order" => 20,
"label" => "City",
"is_required" => false,
"max_choices" => 1,
"validator" => array(
"options" => array(
array("value"=>"1", "text"=>"Delhi"),
array("value"=>"2", "text"=>"Mumbai"),
array("value"=>"3", "text"=>"Alld"),
array("value"=>"4", "text"=>"Varan"),
)
);
$form["field"][] = array(
"name" => "my_custom_fabric",
"type" => "adverts_field_checkbox",
"order" => 20,
"label" => "Choose Fabric",
"is_required" => false,
"validator" => array( ),
"max_choices" => 3,
"options" => array(
array("value"=>"1", "text"=>"Silk"),
array("value"=>"2", "text"=>"Cotton"),
array("value"=>"3", "text"=>"Woollen"),
array("value"=>"4", "text"=>"Polyester"),
)
);
return $form;
}
Next, I inserted the following code for display of fields in Ad Details page. Inserted again in functions.php file
add_action( "adverts_tpl_single_details", "my_adverts_tpl_single_details" );
function my_adverts_tpl_single_details( $post_id ) {
$cf = get_post_meta( $post_id, "my_custom_city", false);
$cc = get_post_meta( $post_id, "my_custom_fabric", false);
?>
<?php if(! empty($cf) ): ?>
<div class="adverts-grid-row">
<div class="adverts-grid-col adverts-col-45">
<span class="adverts-round-icon"></span>
<span class="adverts-row-title">City</span>
</div>
<div class="adverts-grid-col adverts-col-90">
<?php esc_html_e( join(", ", $cf) ) ?>
</div>
</div>
<?php endif; ?>
<?php if(! empty($cc) ): ?>
<div class="adverts-grid-row">
<div class="adverts-grid-col adverts-col-45">
<span class="adverts-round-icon"></span>
<span class="adverts-row-title">Choose Fabric</span>
</div>
<div class="adverts-grid-col adverts-col-90">
<?php esc_html_e( join(", ", $cc) ) ?>
</div>
</div>
<?php endif; ?>
<?php
}
The ADD form works perfectly, however the ‘ad details’ page only shows values 1,2 etc. against these fields, instead of the actual text.
Many thanks for your support