Custom sorting fields doesn’t seem to work properly
- pridigitalParticipant1 year, 7 months ago #35284
Hi there,
I’m facing two issues with the sorting functionality. Here is the scenario explained.In the admin area:
- I have a custom post type (CTP_1)
- I have a “text, sortable” ACF field (ACF_1) configured in the “2.2 Data” tab
- I’ve added ACF_1 to the “2.5 Sorts” tab in WP with the text “My field” for the translation.
In my code:
- I’m using the WPSOLR_Events::WPSOLR_FILTER_SORT_FIELDS filter to override the sort fields for CPT_1
`
add_filter( WPSOLR_Events::WPSOLR_FILTER_SORT_FIELDS, array( ‘x’ );
public function x( $default_sort_fields ) {
return get_post_type() === ‘ACF_1’ ? array(‘acf_1_str_asc’) : $default_sort_fields;
}
`
In the frontend:
- I’m rendering the sort widget
`
the_widget( ‘wpsolr\core\classes\ui\widget\WPSOLR_Widget_Sort’ );
`
All of the above seems to work but… not really.
- The sort widget doesn’t render the translation (“My field”). Instead it shows the field key “ACF_1”
- The sort URL parameter doesn’t get set when a sort option is selected in the widget. It fires a 301 redirects instead.
One more time I appreciate your support with this request! 🙂
wpsolrKeymaster1 year, 7 months ago #35285I’m using the WPSOLR_Events::WPSOLR_FILTER_SORT_FIELDS filter to override the sort fields for CPT_1
You do not need that.
I’ve added ACF_1 to the “2.5 Sorts” tab in WP with the text “My field” for the translation.
This should be enough to see your field in the sort list, with its custom label.
pridigitalParticipant1 year, 7 months ago #35286I’m using the WPSOLR_Events::WPSOLR_FILTER_SORT_FIELDS filter because I want to show different sort options for different post types. However, by doing that the HTML select returns the key for the label instead of the translation.
- This reply was modified 1 year, 7 months ago by pridigital. Reason: more details
pridigitalParticipant1 year, 7 months ago #35296Nope. Only after I manually add it in the code. Which is the weird part because I’ve added it in the backend through the WPSolr interface.
pridigitalParticipantpridigitalParticipant1 year, 7 months ago #35308Yes, but item_number is already an active sort in my sort screen. You can see it in the screenshot I shared before. Am I missing something?
pridigitalParticipant1 year, 7 months ago #35311No, I don’t. I’m using the “Default View”.
pridigitalParticipant1 year, 7 months ago #35362Yes, if I remove my code I see the it. However, it also shows other items that are not supposed to be shown.
Let’s say I have the following scenario:
Tax 1
– Item Number
– Date (should be hidden)
Tax 2
– Price
– DateIf I remove my code then both taxonomies will show the date sort.
pridigitalParticipant1 year, 7 months ago #35376Hi there 🙂 the field name is irrelevant. Those were just examples, but yeah. Let’s say then:
Tax 1
– Item Number (should be hidden)
– Date
Tax 2
– Item Number (should NOT be hidden)
– Price
– Date
You must be logged in to reply to this topic.