• Resolved legentlemanfr

    (@legentlemanfr)


    Hi Greg,

    I have detected a small bug (?) in using custom meta in the form renderer.
    I have created a new meta for ads called “wpa_brand”. One option could be inserted among a long list of brands thanks to “adverts_field_select” form renderer.
    But this meta is added to any new post (page, product, ad…) in WP.
    I don’t know why but it seems that “callback_save” => “adverts_save_multi” and “callback_bind” => “adverts_bind_multi” are triggered for any post (used for adverts_field_select, adverts_field_checkbox and adverts_field_account).
    I have added an if condition to exit the callback if the post has not an ‘advert’ type but I’d like to know why such behavior ?

    Many thanks for your feedback.

    Antoine

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

    (@gwin)

    Hi,
    if i understand correctly only the wpa_brand meta is being added to all of the post types?

    Also, can you paste here the code you are using to add the custom field and save it?

    Thread Starter legentlemanfr

    (@legentlemanfr)

    Hello Greg,

    Thanks for your feedback. Here is the code to add and save the meta field in the WPAdverts form.

    add_filter( “adverts_form_load”, “customize_adverts_add” );
    function customize_adverts_add( $form ) {
    if( $form[‘name’] != “advert” ) {
    return $form;
    }
    // List of brands
    $args = array( ‘hide_empty’ => false, ‘fields’ => ‘tt_ids’,’orderby’ => ‘name’ );
    $brands = yith_wcbr_get_terms(‘yith_product_brand’, $args);
    $brand_name_temp = array();
    $array_init[0] = array(“value” => “0”, “text” => __(“Other”,”adverts”));
    foreach ($brands as $key => $brand_id) {
    $brand = get_term($brand_id);
    $brand_name_temp[] = array(“value” => $brand_id, “text” => $brand->name);
    }
    $brand_name = array_merge ($array_init, $brand_name_temp);

    //Edit WPAdvert form
    $form[“field”][] = array(
    “name” => “wpa_brand”,
    “type” => “adverts_field_select”,
    “order” => 11,
    “label” => __(“Brand”, “adverts”),
    “is_required” => false,
    “validator” => array( array( “name” => “is_required” )),
    “empty_option” => false,
    “max_choices” => 1,
    “options” => $brand_name,
    );
    return $form;
    }

    Plugin Author Greg Winiarski

    (@gwin)

    Thanks, it seems like there is some kind of bug, please try opening a file wpadverts/includes/adverts-post-type.php go to line about 49, replace the line

    
    if ( !$post->post_type == 'advert' ) {
    

    with

    
    if ( $post->post_type != 'advert' ) {
    

    and see if it helps?

    Thread Starter legentlemanfr

    (@legentlemanfr)

    Hello Greg,

    Correction seems to work. I have made several tests and there is no extra meta added to post other than advert.

    Thanks !

    Plugin Author Greg Winiarski

    (@gwin)

    Ok great, thanks for the feedback i will be adding the same update in the next WPAdverts release.

    I am closing this thread for now then.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom meta’ is closed to new replies.