• Resolved Jim R

    (@jim-r)


    One my Tag Archive page, I’m able match the Tag_ID with information in another data table then display that information on the Tag Archive page. I would like to display the same information on the Search Archive page, but the documentation for get_search_query isn’t nearly as complete.

    Here is what I’m using to match my Tag_ID to my custom data table:

    $wp_tagID = get_query_var('tag_id');  
    
    mysql_select_db("jwrbloom_wpHHR");
    
    $query = 'SELECT * FROM wp_playerRank';
    $results = mysql_query($query);
    while($line = mysql_fetch_assoc($results)) {
    
    if ($line['wpID'] == $wp_tagID)  {

    I’d like to extend that to Search Archive, and I”m assuming I would use get_search_query.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Archive Templates, whether they be tag, category, author, or search, could follow the same convention.

    In your tag case, you’re using the ‘tag_id’ query var to in turn extract data from your database.

    In your search template, in your Loop you could use the get_the_tags function to get the tags on a post then use that to get data in your database.

    Note: if your ‘jwrbloom_wpHHR’ were in the same database as your WordPress tables you could simply use the wpdb class to extract that data.

    Thread Starter Jim R

    (@jim-r)

    I figured they followed the same logic. My question is do I do this as part of the same file because I have essentially created a plugin to get the data to my Tag Archive. What I’m missing mentally (i.e.failing to grasp) is how to link my search results (a player’s name) to my data table.

    BTW…jwrbloom_wpHHR is the same database for all of this.

    I’m assuming it needs to get to a point where it reads…

    if ($line['wpID'] == (whatever I have defining my search results)) {

    The problem I’m seeing is my wpID is set up to match the Slug created by Tags. Which for a players name looks like FirstName-LastName. Search results are producing names that look like FirstName+LastName, a + instead of a -.

    Assuming you have a Search Template, then please paste all the code from that template file (e.g. search.php) that is displaying those search results into a pastebin such as wordpress.pastebin.ca, and report the link back here. Maybe someone can spot your problem. Thanks.

    Related:
    Stepping Into Templates
    Template Hierarchy

    Thread Starter Jim R

    (@jim-r)

    I got to playing around with it and figured it out. MUCH easier than I thought, and now I’m wondering if all that I did for the Tag Archive was necessary. In fact, I’m pretty sure now it wasn’t.

    You’ll be able to see the similarities in how I set this up based on what I did above:

    $wp_searchSlug = get_search_query();
    
    mysql_select_db("jwrbloom_wpHHR");
    
    $query = 'SELECT * FROM wp_playerRank';
    $results = mysql_query($query);
    while($line = mysql_fetch_assoc($results)) {
    
    if ($line['nameFirst'].' '.$line['nameLast'] == $wp_searchSlug)  {

    I uploaded that, hoping it would at least just not give me an error, and it worked. I was shocked. For once, logic matched syntax.

    🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Tag Archive and Search Archive…’ is closed to new replies.