• Resolved kowalski

    (@jankowalski)


    Hi, i have just order custom field plugin, but it looks too complicated…
    I M FOLLOWING THIS INSTRUCTIONS https://wpadverts.com/documentation/custom-fields/

    So far i registered custom field with this code and while editing it looks it s working.

    
    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" => "Brand",
            "type" => "adverts_field_checkbox",
            "order" => 25,
            "label" => "Brand",
            "is_required" => false,
            "validator" => array( ),
            "max_choices" => 2,
            "options" => array(
                array("value"=>"1", "text"=>"Mercedes"),
                array("value"=>"2", "text"=>"Audi"),
            )
        );}

    NOW, i ve add this code to functions.php

    add_filter(“manage_edit-advert_columns”, “my_adverts_edit_columns”, 20);

    function my_adverts_edit_columns( $columns ) {
    $columns[“brand”] = “Brand”;
    return $columns;
    }

    add_action(“manage_advert_posts_custom_column”, “my_adverts_manage_post_columns”, 10, 2);

    function my_adverts_manage_post_columns( $column, $post_id ) {
    if($column == “brand”) {
    $cf = get_post_meta( $post_id, ‘brand’, true );
    if(empty($cf)) {
    echo “Empty“;
    } else {
    echo ““.$cf.”“;
    }
    }
    }

    I CAN SEE THE COLUMN BUT IT SAYS EMPTY instead of showing the value.

    What do i do wrong?
    Displaying on Ad Details Page is not working either.

    thanks for help

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

    (@gwin)

    Hi, i sent you a reply to the same question via email.

    Thread Starter kowalski

    (@jankowalski)

    OK, solved!

    Thread Starter kowalski

    (@jankowalski)

    Can I use custom taxonomy where i store all brands and use as data source?
    Can i modify and insted of creating array in functions.php pull datas from taxonomy? I already have all brands in database.

    add_action( "init", "register_data_source" );
    function register_data_source( ) {
        wpadverts_custom_fields_register_data_source(array(
            "name" => "unique-name-here",            // som unique name of your choosing
            "title" => "Brands",                    // this will be visible to users 
            "callback" => "data_source_function"     // function which will list options
        ));
    }
    
    function data_source_function( ) {
        return array(
            array(
                "value" => "apple",
                "text" => "Apple",
                "depth" => 0,
            ),
            array(
                "value" => "banana",
                "text" => "Banana",
                "depth" => 0,
            ),
            array(
                "value" => "orange",
                "text" => "Orange",
                "depth" => 0,
            ),
        );
    }
    • This reply was modified 7 years, 11 months ago by kowalski.
    • This reply was modified 7 years, 11 months ago by kowalski.
    Plugin Author Greg Winiarski

    (@gwin)

    It is possible but the code for using custom taxonomies is a bit more complicated than this, please see for an example code snippet https://github.com/simpliko/wpadverts-snippets/blob/master/custom-fields-taxonomies/custom-fields-taxonomies.php

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘custom fields’ is closed to new replies.