Set title to a query var – how?
-
I’ve got a custom rewrite rule using a query var to intercept the main query. Is it possible to set the title to this query var (the ISBN-number) in some way? If needed I can modify the rewrite rule so that it uses a tag instead. Would that help? Any pointer in the right direction would make me very happy.
add_action( 'init', 'isbn_rewrite_init' ); function isbn_rewrite_init(){ add_rewrite_rule( '^isbn/([0-9]{13})$', 'index.php?isbn=$matches[1]', 'top' ); } add_filter('query_vars', 'isbn_query_var'); function isbn_query_var( $query_vars ){ $query_vars[] = 'isbn'; return $query_vars; } add_action('pre_get_posts', 'include_isbn_queryvar'); function include_isbn_queryvar($query) { if (!is_admin() && $query->is_main_query()) { $isbn = $query->query_vars['isbn']; if (!empty($isbn)) { $query->set('meta_key', 'ISBN'); $query->set('meta_value', $isbn); } } }
The topic ‘Set title to a query var – how?’ is closed to new replies.