• Resolved Beginner9

    (@beginner9)


    Hi Greg,
    Appreciate your great work through this plugin.

    Am having some issues with creating custom select/checkbox fields, per your directions (on your site).

    The display of the actual text doesn’t happen. For eg

    "options" => array(
                array("value"=>"1", "text"=>"Silk"),
                array("value"=>"2", "text"=>"Cotton"),
    	    array("value"=>"3", "text"=>"Woollen"),
                array("value"=>"4", "text"=>"Polyester"),
            )

    In the above, the ad detail page shows 1,2, 3 (or a combination of these in case of multi-select), but not the actual text silk/cotton/woollen etc.
    However, it work fine for simple field text. The problem seems to be only in checkbox/select cases.

    The display of the empty form also happens correctly with coorect choices like silk/cottn etc.

    many thanks for your support &help.

    https://wordpress.org/plugins/wpadverts/

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

    (@gwin)

    Hi, i am not sure can you post your whole custom code here?

    Thread Starter Beginner9

    (@beginner9)

    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

    Plugin Author Greg Winiarski

    (@gwin)

    Please note that in the option for example

    array("value"=>"1", "text"=>"Silk"),

    “value” is data that will be saved in DB, “text” is a label which will be displayed in dropdown, so if you want Ad details pages to display “silk” instead of “1”, your options should be

    array("value"=>"Silk", "text"=>"Silk"),
    Thread Starter Beginner9

    (@beginner9)

    It worked, Sir. Thanks a ton !! 🙂

    Plugin Author Greg Winiarski

    (@gwin)

    Ok, great i am closing the thread 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://wordpress.org/support/view/plugin-reviews/wpadverts

    Thread Starter Beginner9

    (@beginner9)

    Have already given a 5 star rating some time ago.
    If the WordPress portal would allow, I would do it again, but it doesn’t. 🙁
    Many Thanks.

    Plugin Author Greg Winiarski

    (@gwin)

    Ok Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Custom Select/Checkbox Fields not displaying correct data’ is closed to new replies.