• Resolved cannect

    (@cannect)


    Hi all,

    I want to combine two fields to show up in one colomn. Like this:

    $manage_fields = array(
                    'title',
                    'descriptions',
                    'customer.firstname' => array('label' => 'Customer'), // this row combined with this one:
                    'customer.surname' => array('label' => 'Customer'),
                    'created' => array('label' => 'Date')
            );

    Is that possible?

    I cant find anything about it in the great docs, so thats why I ask it ??

    https://www.ads-software.com/extend/plugins/pods/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    No, this is not yet supported. But you can get around it by hooking into any column with a filter to change the value output.

    <?php
    add_filter( 'yourpod_field_value', 'my_combine_fields', 10, 5 );
    
    function my_combine_fields ( $value, $field, $attributes, $row, $obj ) {
        if ( 'your_field' == $field ) {
            $value .= ' ' . $row[ 'your_other_field' ];
        }
    
        return $value;
    }
    ?>
    Thread Starter cannect

    (@cannect)

    Hi Scott,

    Thanks for the answer and sorry for my late reply. I was on another project some days.

    Every pods_ui wp-admin page has a Pod Search function. Can I get the search working on both the fields?

    Thanks!

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    There’s documentation on Pods UI here: https://pods.io/docs/code/pods-ui/

    You can set search_across and/or search_across_picks to true to search across all fields and relationship fields respectively.

    Can you elaborate? I want to join fields first_name and last_name. How could I make them appear in the same (first) column?

    Thread Starter cannect

    (@cannect)

    Hi Gabe462,

    As you can see, the code Scott already provided in this topic must be enough to accomplish this.

    <?php
    add_filter( 'yourpod_field_value', 'my_combine_fields', 10, 5 );
    
    function my_combine_fields ( $value, $field, $attributes, $row, $obj ) {
        if ( 'your_field' == $field ) {
            $value .= ' ' . $row[ 'your_other_field' ];
        }
    
        return $value;
    }
    ?>

    OK, my first reply was inadequate.

    What is ‘yourpod_field_value’? Are you saying that there is a hook created for every pod named ‘nameofpod_field_value’? I’ve not yet found a doc page for this…

    Plugin Contributor Josh Pollock

    (@shelob9)

    Yep:)

    Take a look at classes/PodsUI.php line 3329-332:

    if ( is_object( $this->pod ) )
                                        $row_value = $this->do_hook( $this->pod->pod . '_field_value', $row_value, $field, $attributes, $row );
    
                                    $row_value = $this->do_hook( 'field_value', $row_value, $field, $attributes, $row );

    Thanks for the pointer. I’m wondering if this is the wrong hook, because while I’ve set

    add_filter( 'student_field_value', 'my_combine_fields', 10, 5);

    my test is true:

    has_filter( 'student_field_value', 'my_combine_fields' ) )

    and my echo never prints

    function my_combine_fields( $value, $field, $attributes, $row, $obj ) {
        echo "<!-- my_combine_fields() -->";
        if ( 'first_name' == $field ) {
            $value .= ' ' . $row[ 'last_name' ];
        }
        return $value;
    }

    Any thoughts? Thanks much

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    The filters are all prefixed with pods_ui_, so that filter should be pods_ui_field_value or pods_ui_{your_pod}_field_value, sorry my original reply was incorrect.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Combine two field in UI manage paramters’ is closed to new replies.