Custom endpoint filtering post by custom taxonomies

Solved!!! A friend of my found the way function get_latest_posts_by_term($request) { $parsed_args=[ ‘numberposts’ => 20, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘tax_query’ => array( array ( ‘taxonomy’ => $request[‘slug’], ‘field’ => ‘slug’, ‘terms’ => $request->get_param(‘name’), ) ), ]; $get_posts = new WP_Query; $posts= $get_posts->query( $parsed_args ); //$posts = get_posts($args); if (empty($posts)) { … Read more

How to trim white space in search terms?

I came across the same problem. In my opinion, this should be the default search behavior in WP. The solution is to filter the array of parsed query variables. See the documentation here. Add this to the functions.php file in your theme directory. add_filter(‘request’, function ($query_vars) { if (!is_admin() && !empty($query_vars[‘s’])) { $query_vars[‘s’] = trim($query_vars[‘s’]); … Read more