• Resolved thebillevard

    (@thebillevard)


    Hi, First of all, I’d like to thank everyone in advance for taking the time to read this, and hopefully help me out.

    I have a form with 2 fields:

    <form action="http://www.mysite.com/blah" method="post">
    <input type="text" name="VST1" id="VST1" /><input type="text" name="VST2" id="VST2" />
    <input type="submit" value="ok"/>
    </form>

    I’d LIKE to create a function that:

    1. fetches the two values from the form (VST1 & VST2)
    2. query posts to see if any have these 2 exact values as tags
    3. if post exists with these two tags, it exits function and displays post
    4. if post with tags does not exist, it exits and displays another url

    Any help with putting together this function/query would be greatly appreciated.

    Thanks!

Viewing 15 replies - 1 through 15 (of 27 total)
  • Thread Starter thebillevard

    (@thebillevard)

    ok, so I have the first part of the function working (1 + 2), which is:

    <?php
     $tgs = array();
     $tgs[] = get_query_var('VST1');
     $tgs[] = get_query_var('VST2');
     $tags = implode(",",$tgs);
    query_posts('tag='.$tags);
    ?>

    now I just need to work it out so it displays the entire post, not just the post url, and then I’ll go from there. Any ideas?

    Hi,
    how can I also implement pagination?

    Please help me..
    Thanks!!

    I noticed that the query works perfectly well but if I divide pages for the search result pages do not work ..

    Merge your query parameters with those that exist for the current query already, ie. paging values, etc..

    <?php
    // Args as array
    $args = array( 'tag__in' => array(
         get_query_var('VST1'),
         get_query_var('VST2')
    ) );
    // Merge args with existings args
    $args = array_merge( $args, $wp_query->query );
    
    // Pass args into query
    query_posts( $args );
    ?>

    Hope that helps..

    Thanks Mark…
    the code that I’ve used is:

    <?php
    $tgs = array();
    $tgs[] = get_query_var('VST1');
    $tags = implode(",",$tgs);
    query_posts('tag='.$tags);
    ?>

    and it works fine but the pagination does not work, if I click on the second page I see the rest of the post but always those of the first page.

    excuse my English but I’m Italian πŸ™‚

    The result of the first page of this research is:
    http://www.artofweb.it/help/1.jpg

    The second this:
    http://www.artofweb.it/help/2.jpg

    as you can see nothing changes..

    Did you try the code provided?

    Yes I tried, but no longer even the tag ..

    // Args as array
    $args = array( 'tag__in' => array(
         get_query_var('VST1')
    ) );
    // Merge args with existings args
    $args = array_merge( $args, $wp_query->query );
    
    // Pass args into query
    query_posts( $args );
    ?>

    Are you registering the two query vars you’re trying to fetch?

    VST1 and VST2..

    Does echo get_query_var('VST1'); give any result?

    Hi Mark,
    I use ‘VST1’ will use only because I need only a search string!

    If you put this code in your file.
    Translation: Se mettete questo codice, nel vostro file.

    echo get_query_var('VST1');

    Is a value shown on the page?
    Translation: È un valore indicato sulla pagina?

    nothing, I always return the same result

    Try using..

    $_POST['VST1']

    Is this code running on the page your form submits to? That’s the URL the form’s action points at..

    <form action="http://where?"

    Thanks for the help Mark,
    but I can not figure out where I enter the code that I’ve posted. I attach the code I used to run my search page. “VST1″is replaced by “s”. Anyway it works perfectly and I can only do research just like I wanted to tag, the only problem is paging.

    <form method="get" action="<?php bloginfo('url'); ?>/"><input type="text" size="20" class="search-field-teaser" name="s" id="s" value="" onfocus="if(this.value == '') {this.value = '';}" onblur="if (this.value == '') {this.value = '';}"/>
     <button type="submit"  value="Search" class="search-go fancy_button"><span>Cerca</span></button></p>
    </form>
    
    <?php
    $tgs = array();
    $tgs[] = get_query_var('s');
    $tags = implode(",",$tgs);
    query_posts('tag='.$tags);
    ?>

    Thanks again for your patience..

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Query Tags From Text Form’ is closed to new replies.