Help w/custom query variable and rewrite/permalink (5 posts)

  1. fivehead
    Posted 5 years ago #

    I am working on something very similar to TheMarco's problem. Sadly, I'm not yet WordPress-proficient-enough to adapt it to my situation. Hoping you can help.
    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: http://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 (thanks, Otto):

    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 the code:

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

    Assuming I need to add some wp_rewrite rules as well to functions.php, but we all know what assuming does.
    At this point, a single response would be absolutely A+, as I'm frustrated as all gitup. Many thanks.

  2. coopersita
    Posted 5 years ago #

    I think you are complicating things too much. Have you tried using custom posts, and custom taxonomies? That's how I would do it:


    Plugins for it:

  3. fivehead
    Posted 5 years ago #

    Many thanks for the reply, coopersita. I previously thought custom post types were my answer. However, I decided against it because the custom post type would be the quote, but also capture the quote author and all of his/her info. This is fine if a quote author only has one quote, but if a person has a hundred different quotes, I'm storing a new (but same) quote author with each one of those quotes. Not a big deal at first, but I fancy it as a scaling decision thing once things take off. Also, for me, the quote author is almost important as the quote, so I want to build in as much flexibility as possible for quote author.
    Thanks again for the reply and info you sent. I will take another stroll through it, to see if I have an a-ha moment.

  4. coopersita
    Posted 5 years ago #

    If you set your post type as "Quote", with a custom taxonomy of "Quote Author", you don't need to set a new, but same, author every time. You just select it from the list (you just need to set authors as hierarchical). You can make it quite fancy:

    But how about you set 2 custom post types: "Quotes" and "Authors", and then with a custom field, you associate the right quote, with the right author. Something like this:

    Just some ideas...

  5. fivehead
    Posted 5 years ago #

    Thanks for the ideas Coopersita. I am working on your 2nd suggestion of the 2 custom post types, so that when a quote is submitted, 2 posts are created: 1)quote author, returning the post id 2)quote, then update post_meta, using the quote author post id to tie the author to the quote.

    Just wanted to give a quick update so you didn't think I was a hog and jogger! As always, any feedback on approach is appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic