Modifying Listings Fields Display

Type: Filter
Name: td_shown_listings_fields
Location: wp-trade/inc/TD_Posts.class.php
No. of Parameters: 4

td_shown_listings_fields_filter_screenshot
 

Adding New Field(s)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function my_shown_listings_fields( $shown_listings_fields, $post, $post_meta, $author ) {
   
    // Add new fields
    $additions = array(
        'item_id'           => '<span class = "glyphicon glyphicon-adjust"></span> ' . __('Post ID') . ': ' . $post->ID,
        'item_status'       => '<span class = "glyphicon glyphicon-fire"></span> ' . __('Status') . ': ' . $post_meta['td_status'],
        'item_author_email' => '<span class = "glyphicon glyphicon-certificate"></span> ' . __('Author Email') . ': <a href = "mailto:' . $author->user_email . '">' . $author->user_email . '</a>'
    );
   
    $shown_listings_fields = array_merge( $shown_listings_fields, $additions );
   
    return $shown_listings_fields;
   
}
add_filter('td_shown_listings_fields', 'my_shown_listings_fields', 10, 4);

Available items that you can add
$post (object)
$post_meta (array)
$author (object)

Default fields that are shown:

1
2
3
4
5
'item_content'      => cvf_limit_words( strip_tags( $post->post_content ), 50 ),
'item_postdate'     => '<span class = "glyphicon glyphicon-time"></span> ' . self::cvf_td_posted_on( $post->ID ),
'item_location'     => '<span class = "glyphicon glyphicon-map-marker"></span> ' . $author->td_city . ', ' . $author->td_country_2x_format,
'item_condition'    => '<span class = "glyphicon glyphicon-eye-open"></span> Condition: ' . ucfirst( $post_meta['td_condition'] ),
'item_author'       => '<span class = "glyphicon glyphicon-user"></span> Author: <a href = "' . get_author_posts_url( $author->ID ) . '">' . $author->user_login . '</a>'

Using Glyphicons
Format:

1
<span class = "glyphicon glyphicon-adjust"></span>

List of Glyphicons: http://getbootstrap.com/components/

Modifying Field(s)

1
2
3
4
5
6
7
8
9
10
11
12
13
function my_shown_listings_fields( $shown_listings_fields, $post, $post_meta, $author ) {
   
    // Example of modifying field(s)
    $mods = array(
        'item_content'      => cvf_limit_words( strip_tags( $post->post_content ), 10 ), // This will modify the existing 'item_content'
    );
   
    $shown_listings_fields = array_merge( $shown_listings_fields, $mods );
   
    return $shown_listings_fields;
   
}
add_filter('td_shown_listings_fields', 'my_shown_listings_fields', 10, 4);

Removing Field(s)

1
2
3
4
5
6
7
8
9
10
11
12
function my_shown_listings_fields( $shown_listings_fields, $post, $post_meta, $author ) {
   
    // Example of removing fields
    unset(
        $shown_listings_fields['item_condition'],
        $shown_listings_fields['item_author']
    );
   
    return $shown_listings_fields;
   
}
add_filter('td_shown_listings_fields', 'my_shown_listings_fields', 10, 4);

Re-arrangnging items

You will have to remove all options first then re-define a new array for $shown_listings_fields which will contain the values in the order you want. No need to use array_merge, just return the sorted array.



Do you need help with a project? or have a new project in mind that you need help with?

Contact Me