Okay
  Public Ticket #2226290
Add custom field to portfolio item overview
Closed

Comments

  • c_gschoesser started the conversation

    Hi there,

    I am using your template for the third time. I like it very much but now I need an additional feature.
    I am a developer form austria and currently making the website of an apartment. 

    I would like to add a custom text field for the smallest price. Can you tell me the files which I have to edit to add a custom text field within the item details. (field.png). Where can I register another text field?

    And I would like to display it as a <div> within the <div class="info"> or right after it.

    I want to positon it absolute like in preis.png e.g.
    Which file is the template for the portfolio items?

    Thank you in advance for your support.

    Best regards,

    Christian

  • [deleted] replied

    Hi Christian,

    Sorry for delay of reply.

    To add custom text field and avoid editing parent theme files you should add this code in functions.php of child theme:

    add_filter( 'acf/validate_field_group', function ( $field_group ) {
        if ( 'group_5ba0c487b1831' === $field_group['key'] ) {
            $sub1 = array_slice( $field_group['fields'], 0, 2 );
            $sub2 = array_slice( $field_group['fields'], 2 );
            $my_custom_fields = array(
                // Smallest price field
                array(
                    'key'               => 'field_119716d5eb33f',
                    'label'             => 'Smallest Price',
                    'name'              => 'smallest_price',
                    'type'              => 'text',
                    'instructions'      => 'Enter smallest price.',
                    'required'          => 0,
                    'conditional_logic' => 0,
                    'wrapper'           => array(
                        'width' => '',
                        'class' => '',
                        'id'    => '',
                    ),
                    'default_value'     => '',
                    'placeholder'       => '',
                    'prepend'           => '',
                    'append'            => '',
                    'formatting'        => 'html',
                    'maxlength'         => '',
                )
            );
            $field_group['fields'] = array_merge(
                $sub1,
                $my_custom_fields,
                $sub2
            );
        }
        return $field_group;
    } );
    
    So the field will be available in General Details Tab:

    https://d.pr/v/JCbByd

    After this, to display the field you should add this code in functions.php:

    add_action( 'kalium_portfolio_loop_item_categories_after', function() {
       $smallest_price = kalium()->acf->get_field( 'smallest_price' );
        echo sprintf( '<div class="smallest-price">%s €</div>', number_format( $smallest_price, 2 ) );
    } );

    This should work for you and also do not care if you update the parent Kalium theme or not.