Description
Bug description
When accessing the API with specific parameters related to taxonomy, the following error occurs:
Undefined variable: order in /var/www/html/public/wp-content/plugins/tainacan/classes/api/endpoints/class-tainacan-rest-items-controller.php on line 544.
How to reproduce such bug
Use the following steps to reproduce the issue:
1. Make an API request to the endpoint /wp-json/tainacan/v2/items
with parameters including taxonomy-related filters (e.g., ?taxquery[0][taxonomy]=tnc_tax_90498&taxquery[0][terms]=17881&taxquery[0][compare]=IN).
2. Observe the response.
Expected behavior
The API should return the filtered items based on the taxonomy parameters without triggering an error.
Additional context
The error occurs because the $order variable is only initialized if a certain condition within an if statement is met. If the condition is not satisfied, $order remains undefined, leading to the error when it’s used in the line 544. Below is the relevant snippet of the code:
Potential fix:
Ensure $order is always initialized regardless of the condition.