WordPress.org

Ready to get started?Download WordPress

Forums

Pods - Custom Content Types and Fields
[resolved] Combine two field in UI manage paramters (10 posts)

  1. cannect
    Member
    Posted 1 year ago #

    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 :)

    http://wordpress.org/extend/plugins/pods/

  2. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

    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;
    }
    ?>
  3. cannect
    Member
    Posted 1 year ago #

    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!

  4. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 1 year ago #

    There's documentation on Pods UI here: http://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.

  5. Gabe462
    Member
    Posted 8 months ago #

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

  6. cannect
    Member
    Posted 8 months ago #

    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;
    }
    ?>
  7. Gabe462
    Member
    Posted 8 months ago #

    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...

  8. Josh Pollock
    Member
    Plugin Author

    Posted 8 months ago #

    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 );
  9. Gabe462
    Member
    Posted 8 months ago #

    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

  10. Scott Kingsley Clark
    Member
    Plugin Author

    Posted 8 months ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic