• Resolved Fanneau

    (@fanneau)


    Hi,

    Your plugin is great. Thanks for that.
    But I add custom fields.
    All custom fields works except : checkbox when we fill the form in Front office.

    Example :
    From back office :
    I add an advert, I fill all the form. I go to the advert on front office. Everything is ok.
    https://www.ubianimo.com/advert/zoubida/ : tempérament et particularités are OK.

    From front office :
    I add an advert, I fill all the form. I have to preview.
    The preview doesn’t show anything where I must be my choices in checkboxes.
    When I validate the preview it the same. Everything is ok except the choices in checkbox who are not displayed at all.
    When I modify i can see that my choices in checkboxes are not saved, and it’s the fist checkbox which is selected.
    Saved my modifications don’t work better.
    https://www.ubianimo.com/advert/seguine/ : tempérament et particularités are not OK.

    I try from wpadvert 1.0.8 to last version.
    I keep 1.0.8 because it’s certainly with this version that I begin to personnalize a-advert on this website.

    Thank you for your support.

    Fanneau

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, can you let me know what code are you using to display and save the custom fields?

    Thread Starter Fanneau

    (@fanneau)

    <?php

    /*——————————————-
    ——-AJOUT DE CHAMP POUR L’ANNONCE ——–
    ——————————————-*/
    add_filter( “adverts_form_load”, “my_adverts_form_load” );
    function my_adverts_form_load( $form ) {

    if( $form[“name”] != “advert” ) {
    return $form;
    }

    // FICHE D’IDENTITE

    $form[“field”][] = array(
    “name” => “fiche_identite”,
    “type” => “adverts_field_header”,
    “order” => 25,
    “label” => “Fiche d’identité”,
    );

    $form[“field”][] = array(
    “name” => “nom”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “Nom”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );

    $form[“field”][] = array(
    “name” => “sexe”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “Sexe”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );

    $form[“field”][] = array(
    “name” => “age”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “Age”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );

    $form[“field”][] = array(
    “name” => “race”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “Race”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );

    /*
    $form[“field”][] = array(
    “name” => “lof”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “LOF / LOOF”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );
    */

    $form[“field”][] = array(
    “name” => “lofloof”,
    “type” => “adverts_field_radio”,
    “order” => 25,
    “label” => “LOF / LOOF”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    ),
    “max_choices” => 1,
    “options” => array(
    array(“value”=>”Oui”, “text”=>”Oui”),
    array(“value”=>”Non”, “text”=>”Non”),
    )
    );

    $form[“field”][] = array(
    “name” => “departement”,
    “type” => “adverts_field_text”,
    “order” => 25,
    “label” => “Département”,
    “is_required” => true,
    “validator” => array(
    array( “name” => “is_required” ),
    )
    );

    //TEMPERAMMENT

    $form[“field”][] = array(
    “name” => “temperamment_header”,
    “type” => “adverts_field_header”,
    “order” => 25,
    “label” => “Tempéramment”,
    );

    $form[“field”][] = array(
    “name” => “temperamment”,
    “type” => “adverts_field_checkbox”,
    “order” => 25,
    “label” => “Tempéramment”,
    “is_required” => false,
    “validator” => array( ),
    “max_choices” => 6,
    “options” => array(
    array(“value”=>”Sociable”, “text”=>”Sociable”),
    array(“value”=>”Joueur”, “text”=>”Joueur”),
    array(“value”=>”Dynamique”, “text”=>”Dynamique”),
    array(“value”=>”Calin”, “text”=>”Calin”),
    array(“value”=>”Calme”, “text”=>”Calme”),
    array(“value”=>”Gardien”, “text”=>”Gardienbla”),
    )
    );

    $form[“field”][] = array(
    “name” => “temperamment_autre”,
    “type” => “adverts_field_textarea”,
    “order” => 25,
    “label” => “Autre”,
    “is_required” => false,
    “validator” => array( ),

    “mode” => “plain-text”
    );

    //PARTICULARITES

    $form[“field”][] = array(
    “name” => “particularites_headers”,
    “type” => “adverts_field_header”,
    “order” => 25,
    “label” => “Particularités”,
    );

    $form[“field”][] = array(
    “name” => “particularites”,
    “type” => “adverts_field_checkbox”,
    “order” => 25,
    “label” => ” “,
    “is_required” => false,
    “validator” => array( ),
    “max_choices” => 6,
    “options” => array(
    array(“value”=>”N’aime pas les enfants”, “text”=>”N’aime pas les enfants”),
    array(“value”=>”Peut vivre en appartement”, “text”=>”Peut vivre en appartement”),
    array(“value”=>”Besoin de se dépenser”, “text”=>”Besoin de se dépenser”),
    array(“value”=>”Besoin d’attention”, “text”=>”Besoin d’attention”),

    )
    );

    //CONDITIONS D’ADOPTION

    $form[“field”][] = array(
    “name” => “condition_adoption_header”,
    “type” => “adverts_field_header”,
    “order” => 25,
    “label” => “Condition d’adoption”,
    );

    $form[“field”][] = array(
    “name” => “condition_adoption”,
    “type” => “adverts_field_textarea”,
    “order” => 25,
    “label” => ” “,
    “is_required” => false,
    “mode” => “plain-text”,
    “placeholder” => “Indiquer les frais de vétérinaire…”,
    );

    return $form;

    }

    /*——————————————-
    —-SUPPRIMER LES CHAMPS PAR DEFAULT ——–
    ——————————————-*/

    add_filter( “adverts_form_load”, “my_adverts_form_remove_fields” );
    function my_adverts_form_remove_fields( $form ) {
    if($form[“name”] != “advert”) {
    return $form;
    }

    $to_remove = array(“adverts_price”, “adverts_location”, “_item_information”);

    foreach($form[“field”] as $k => $field) {
    if(in_array($field[“name”], $to_remove)) {
    unset($form[“field”][$k]);
    }
    }

    return $form;
    }

    /*——————————————-
    —AJOUT DES CHAMPS SUR LA PAGE D’ANNONCE —-
    ——————————————-*/

    add_action( “adverts_tpl_single_details”, “my_adverts_tpl_single_details” );
    function my_adverts_tpl_single_details( $post_id ) {
    $nom = get_post_meta( $post_id, “nom”, true);
    $sexe = get_post_meta( $post_id, “sexe”, true);
    $temperamment = get_post_meta( $post_id, “temperamment”, true);
    var_dump($temperamment);
    $age = get_post_meta( $post_id, “age”, true);
    /*$lof = get_post_meta( $post_id, “lof”, true);*/
    $lofloof = get_post_meta( $post_id, “lofloof”, true);
    $race = get_post_meta( $post_id, “race”, true);
    $temperamment_autre = get_post_meta( $post_id, “temperamment_autre”, true);
    $particularites = get_post_meta( $post_id, “particularites”, true);
    $condition_adoption= get_post_meta( $post_id, “condition_adoption”, true);
    $departement= get_post_meta( $post_id, “departement”, true);
    ?>
    <br>
    <?php if(! empty($nom) ): ?>
    <div class=”adverts-grid-row”>
    <h4>Fiche d’identité</h4>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-info-circle” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>Nom</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $nom ) ?>
    </div>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-info-circle” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>Race</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $race ) ?>
    </div>
    </div>
    <?php endif; ?>

    <?php if(! empty($sexe) ): ?>
    <div class=”adverts-grid-row”>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-venus-mars” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>Sexe</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $sexe ) ?>
    </div>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-info-circle” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>LOF / LOOF</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $lofloof ) ?>
    </div>
    </div>
    <?php endif; ?>

    <?php if(! empty($age) ): ?>
    <div class=”adverts-grid-row”>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-birthday-cake” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>Age</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $age ) ?>
    </div>
    <div class=”adverts-grid-col adverts-col-20″>
    <i class=”fa fa-map-marker” aria-hidden=”true”></i>
    <span class=”adverts-row-title” style=”font-weight:bold;”>Département</span>
    </div>
    <div class=”adverts-grid-col adverts-col-30″>
    <?php esc_html_e( $departement ) ?>
    </div>
    </div>
    <br>
    <?php endif; ?>

    <?php if(! empty($temperamment) ): ?>
    <div class=”adverts-grid-row”>
    <h4>Tempéramment</h4>
    <div class=”adverts-grid-col adverts-col-100″>
    <?php array_push($temperamment, $temperamment_autre); ?>
    <?php esc_html_e( join(” – “, $temperamment) ) ?>
    </div>
    </div>
    <br>
    <?php endif; ?>

    <?php if(! empty($particularites ) ): ?>
    <div class=”adverts-grid-row”>
    <h4>Particularité</h4>
    <div class=”adverts-grid-col adverts-col-100″>
    <?php esc_html_e( join(” – “, $particularites) ) ?>
    </div>
    </div>
    <br>
    <?php endif; ?>

    <?php if(! empty($condition_adoption ) ): ?>
    <div class=”adverts-grid-row”>
    <h4>Condition d’adoption</h4>
    <div class=”adverts-grid-col adverts-col-100″>
    <?php esc_html_e( $condition_adoption) ?>
    </div>
    </div>
    <?php endif; ?>
    <br>
    <h4>Description</h4>
    <?php
    }

    Thread Starter Fanneau

    (@fanneau)

    //TEMPERAMMENT and //PARTICULARITES doesn’t work

    Thank you ??

    • This reply was modified 8 years, 4 months ago by Fanneau.
    Plugin Author Greg Winiarski

    (@gwin)

    If the input can have more than one value, you should load it as

    
    $temperamment = get_post_meta( $post_id, "temperamment", false);
    

    not

    
    $temperamment = get_post_meta( $post_id, "temperamment", true);
    

    the last param is $is_single and determines if only one value for this meta field should be loaded or all of them.

    Thread Starter Fanneau

    (@fanneau)

    Great !
    Thank you very much for very good support.

    Plugin Author Greg Winiarski

    (@gwin)

    Sure, no problem i am marking this thread as resolved then :).

    BTW. If you are finding the plugin useful i would be thankful if you could write a short one or two sentence review here https://www.ads-software.com/support/view/plugin-reviews/wpadverts

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom field, check box not displayed when add advert from front office’ is closed to new replies.