• Lisa C

    (@lisathirdsideco)


    I’m using AgentPress for a client’s real estate site, but the dropdown options in the search widget aren’t sorting correctly. On the Office page, the office rent taxonomies were registered in order from smallest amount to largest, but they don’t display that way. According to my understanding, the search widget should sort by ID from smallest number to largest. Any idea why it isn’t doing that?

    https://1-main.com/propertytype/office/

Viewing 3 replies - 1 through 3 (of 3 total)
  • I am also having this issue. I downloaded the Taxonomies Reorder plugin, but actually it is not the taxonomies, it is the dropdown items of each taxonomy that are in the wrong order. So that plugin doesn’t help. Any ideas from anyone out there?

    Plugin Support Nick C

    (@modernnerd)

    The search widget drop-down options display based on the ‘count’ of Listings for each taxonomy term (terms with the most listings will appear first in each drop-down).

    There is no AgentPress-specific filter to change the order, but you could filter on get_terms, like this:

    add_filter( 'get_terms', 'custom_agentpress_term_sort_order', 10, 4 );
    /**
     * Change AgentPress to sort taxonomy by ID instead of by count.
     *
     * @param array         $terms      Array of found terms.
     * @param array         $taxonomies An array of taxonomies.
     * @param array         $args       An array of get_terms() arguments.
     * @param WP_Term_Query $term_query The WP_Term_Query object.
     * @return array
     */
    function custom_agentpress_term_sort_order( $terms, array $taxonomies, array $args, $term_query ) {
    	if ( is_admin() ) {
    		return $terms;
    	}
    
    	if ( in_array( 'area', $taxonomies, true ) ) {
    		$args['orderby'] = 'ID';
    		$args['order'] = 'ASC';
    		return $term_query->query( $args );
    	}
    
    	return $terms;
    }

    Add the code to your active theme’s functions.php file, then replace ‘area’ with your taxonomy slug as it appears in the Listings → Register Taxonomies section.

    You could repeat the second if block for each taxonomy and specify the orderby and order values for each term.

    • This reply was modified 7 years, 2 months ago by Nick C.

    Thank you so much, Nick Cernis, you are brilliant. This worked perfectly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Search Widget dropdown display issue’ is closed to new replies.