loop in single.php of the same category

I suggest the following: $categories = get_the_category(); $category_ids = wp_list_pluck( $categories, ‘term_id’ ); $args = [ ‘numberposts’ => 4, ‘category__in’ => $category_ids, ]; $related_posts = get_posts( $args ); $related_posts = wp_list_filter( $related_posts, [ ‘ID’ => get_queried_oject_id() ], ‘NOT’ ); if ( count( $related_posts > 3 ) ) { array_pop( $related_posts ); } global $post; foreach … Read more

Category pages resolving with and without category prefix

I didn’t find the cause. But I was able to hack a solution into functions.php: add_action(“wp”, “disable_duplicate_categories”); function disable_duplicate_categories() { if (is_category()) { $urlParts = explode(“https://wordpress.stackexchange.com/”, $_SERVER[“REQUEST_URI”]); if ($urlParts[1] !== ‘category’) { array_splice($urlParts, 1, 0, ‘category’); $url = implode(“https://wordpress.stackexchange.com/”, $urlParts); header(“Location: “.$url,TRUE,301); exit; } } } The unwanted pages are never linked to, so the … Read more