[wp-hackers] sortable taxonomy columns for taxonomy metadata

Roberto Sanchez roberto at digitalbrands.com
Mon Jan 14 20:41:22 UTC 2013


Hi,

I posted this question here:
http://wordpress.stackexchange.com/questions/80095/sortable-taxonomy-columns-for-taxonomy-metadata

Hoping for some assistance from wp-hackers.

I have a column displayed in a custom taxonomy page, which is displayed
under a custom post type. Now I already registered the column and get it to
display like this:

    add_action( 'manage_merchant_custom_column',
'display_pageviews_column', 10, 3 );
    function display_pageviews_column( $column, $column2, $term_id ) {
        if ( $column2 == 'pageviews' ) {
            $merchant_term = get_term_by( 'id', $term_id, 'merchant' );
            $pageviews = get_metadata( 'taxonomy', $merchant_term->term_id,
'pageviews', true );
            echo $pageviews;
        }
    }

I have a pageviews column in the merchant taxonomy page.

Now I also made the column sortable, so when I click on the column header,
the query vars in the url look like this:


edit-tags.php?taxonomy=merchant&post_type=coupon&orderby=pageviews&order=asc

However, the problem I'm having is that the query vars just don't get to
the backend. Additionally, even when I don't check for the query vars, the
list is not being sorted.

Here is what I'm trying to do for sorting logic:

    add_action( 'pre_get_posts', 'testing_pre_get_posts' );
        function testing_pre_get_posts( &$query ) {
        $orderby = $query->get( 'orderby' );
        if ( 'pageviews' == $orderby ) {
            $query->set( 'meta_key', 'pageviews' );
            $query->set( 'orderby', 'meta_value_num' );
        }
    }

I added some error_logs and $query->get( 'orderby' ) returns nothing.
However, even if I remove that condition, $query->set() is not doing
anything either. There is no sorting when I click on the column header to
sort.

How am I supposed to order by taxonomy metadata? I appreciate any
assistance with this.

Thanks,

Roberto


More information about the wp-hackers mailing list