• I want to use a custom taxnomy with this plugin.

    It is registered as following:

    register_taxonomy( 'icon', 'post', array(
    		'sort' => true,
    		'args' => array(
    			'orderby' => 'term_order',
    		),
    	) );

    It is expected to be done as following automatically.

    1) get_terms() are orderd by this plugin
    ex. a menu of link to archive pages.

    2) wp_get_object_terms() are orderd for each posts
    ex. list related terms by attached order in single post pages.

    but 2) will also be overrided with this plugin even if 'orderby' => 'term_order' is already recognized as ‘tr.term_order’ by WP core.

    In TO_get_terms_orderby(),

                if (isset($args['orderby']) && $args['orderby'] == "term_order" && $orderby != "term_order")
                    return "t.term_order";

    For case 2), $args['orderby'] == "term_order" && $orderby == "tr.term_order", not $orderby == "term_order".
    How about adding the condition $orderby != "tr.term_order" too?

    It is possible do as above with following filter:

    add_filter( 'to/get_terms_orderby/ignore', function( $ignore, $orderby, $args ) {
    	if ( !$ignore && isset($args['orderby']) && $args['orderby'] == "term_order" && $orderby === 'tr.term_order' ) {
    		$ignore = true;
    	}
    	return $ignore;
    },10, 3);

    orderby clause is also changed with TO_get_terms_orderby later and it is using to/get_terms_orderby/ignore filter too.
    But 2nd argment is orderby clause ‘ORDER BY tr.term_order` here, not plain ‘tr.term_order’.
    It might be hard to filter different conditions with one filter, but
    adding 'ignore_term_order' => true to args for register_taxnomy will avoid the issue now.

  • The topic ‘How to work together with terms registered as ‘orderby’ => ‘term_order’ ?’ is closed to new replies.