Found the solution:
functions.php:
add_action('init', 'wp_university_full_rewrite');
function wp_university_full_rewrite() {
add_rewrite_rule(
'university/([^/]*)/?$',
'index.php?pagename=university&uni_name=$matches[1]',
'top');
}
add_filter('query_vars', 'wp_university_full_query_vars');
function wp_university_full_query_vars( $query_vars ) {
$query_vars[] = 'uni_name';
return $query_vars ;
}
function get_data_with_query( $name_query ) {
$data = [];
global $wpdb;
$data = $wpdb->get_row("SELECT * FROM table WHERE name="".$name_query.""", ARRAY_A );
return $data;
}
custom_template.php:
<?php $name_pull = get_query_var('uni_name') ?>
<?php $uni_data2 = get_data_with_query($name_pull) ?>
and there is a page with slug ‘university’ that has its template as my_custom_template.
I know this is a very crude way of doing things, so now it’s time to wrap everything in if statements and error pages!!