Fix request problem with the same base url from posts and categories

/** * custom_fix_category_requests * Como categorias y post del blog tienen la misma url base, [blog], tenemos que * filtrar la request para si no encuentra la categoria que viene como * category_name, reconvertirla en name en el request para mostrar un post del * blog * * @param Array $request * @return Array */ function custom_fix_category_requests( $request ) { if (array_key_exists( 'category_name' , $request ) && ! get_term_by( 'slug', basename( $request['category_name'] ), 'category' )) { $request['name'] = basename( $request['category_name'] ); unset( $request['category_name'] ); } return $request; } add_filter( 'request', 'custom_fix_category_requests' );

1 Response

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.