What I have: A site of quotes with format: "Quote text." -Quote Author
See quotup.com for my test website (my apologies in advance for the testing-profanity).

What I'm after: Clicking "-Quote Author" should launch a page of all quotes by that quote author with URL: example.com/SteveStevenson, where Steve Stevenson is the Quote Author.

What I've done: Created a custom table called wp_qauthor that is tied to wp_posts by post_meta (qauthor_id).
Added the following code to functions.php:

add_filter('query_vars', 'add_my_var');
    function add_my_var($public_query_vars) {
        $public_query_vars[] = 'qaid';
        return $public_query_vars;

Created a link for the Quote Author's name as such:

<a href="http://example.com?qaid=2">Steve Stevenson</a>

Clicking on this link currently loads home.php, but I need it to hit index.php, where I've added this code:

elseif (get_query_var('qaid')) {
    $qaid = get_query_var('qaid');
    query_posts($query_string . "&meta_key=qauthor_id&meta_value=" . $qaid);}

The questions:

  • How do I tell WP to call index.php when I click the example.com?qaid=2 href?
  • After clicking the link above, how do I get the desired pretty link of example.com/SteveStevenson?
    Many Thanks!

2 Answers 2


Create a custom taxonomy quoteauthor, activate pretty permalinks, and you get nice URIs automatically. These URIs will not put the author’s name right behind the root, but something like /qa/steve-stevenson/ should be good enough.

Here is a sample code as a plugin, you can download it on GitHub

<?php # -*- coding: utf-8 -*-
Plugin Name: Custom Taxonomy Quote Author
Plugin URI:  https://gist.github.com/996608
Description: Creates a custom taxonomy <code>Quote Author</code> with an URI <code>/qa/author-name/</code>
Version:     1.0
Required:    3.1
Author:      Thomas Scholz
Author URI:  http://toscho.de
License:     GPL
! defined( 'ABSPATH' ) and exit;

add_action( 'after_setup_theme', 'register_quote_author' );

register_activation_hook(   __FILE__, 'qua_flush' );
register_deactivation_hook( __FILE__, 'qua_flush' );

 * Registers the taxonomy 'Quote Author'.
 * To list the authors with links in your theme use
 * @link http://codex.wordpress.org/Function_Reference/get_the_term_list
 * <code>print get_the_term_list( get_the_ID(), 'quoteauthor' );</code>
 * @link http://codex.wordpress.org/Function_Reference/register_taxonomy
 * @return void
function register_quote_author()
        // Internal name
        // Post types the taxonomy applies to.
        // The attachment field is not very nice, just a simple input field.
        // You may tweak that.
    ,   array ( 'post', 'attachment' )
        // Visible labels
    ,   array (
        'labels'            => array (
            'name'                       => 'Quote Authors'
        ,   'menu_name'                  => 'Quote Authors'
        ,   'singular_name'              => 'Quote Author'
        ,   'search_items'               => 'Search Quote Authors'
        ,   'popular_items'              => 'Popular Quote Authors'
        ,   'all_items'                  => 'All Quote Authors'
        ,   'edit_item'                  => 'Edit Quote Author'
        ,   'update_item'                => 'Update Quote Author'
        ,   'add_new_item'               => 'Add Quote Author'
        ,   'new_item_name'              => 'New name for Quote Author'
        ,   'separate_items_with_commas' => 'Separate Quote Authors by comma'
        ,   'add_or_remove_items'        => 'Add or remove Quote Authors'
        ,   'choose_from_most_used'      => 'Choose from most quoted authors'
        // Most important parameter. :)
    ,   'public'            => TRUE
        // Available in custom menus.
    ,   'show_in_nav_menus' => TRUE
        // Standard box.
    ,   'show_ui'           => TRUE
        // Clickable list of popular authors.
    ,   'show_tagcloud'     => TRUE
        // URI
    ,   'rewrite'           => array (
            'slug' => 'qa'
        // If you want to use WP_Query.
    ,   'query_var'         => 'qa'
 * Tells WordPress to rebuild the rewrite rules to include our custom URIS.
 * @return void
function qua_flush()
    // The current instance of the class WP_Rewrite.
    global $wp_rewrite;
  • Holy, thanks for all this work. Sorry to leave you hanging...damn real world got in the way. I'm working through this and will report back.
    – fivehead
    Jun 6, 2011 at 3:59

Q: How do I tell WP to call index.php when I click the example.zom?qaid=2 href?
A: Well if your talking about the template file as longs as there no template in your theme for author.php you should be fine. Or as long as there are no templates to interfere with loading index.php it should load it by default

Q: After clicking the link above, how do I get the desired pretty link of example.com/SteveStevenson? Many Thanks!
A: This can be found under the settings tab in your back-end under permalinks and as long as your server allows mod_rewrite and you have inserted the .htaccess file should work automatically


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.