WordPress.org

Support

Support » How-To and Troubleshooting » Create "template links" that are making search queries

Create "template links" that are making search queries

  • bumTomica
    Member

    @bumtomica

    Hy,

    Is there any way to make a template “a href” link, when on click, the WP would make a search?

    Like, I’m doing this now, it works, but I would like to know if it can be coded better.

    <a href="http://simplynote.me/?s=<?php echo $autori->autor ?>"><?php echo $autori->autor ?></a>

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi
    Forum Moderator

    @esmi

    <a href="<?php echo esc_url( home_url( '/' ) ); ?>?s=<?php echo $autori->autor ?>"><?php echo $autori->autor ?></a>

    would be better. Not sure what $autori->autor refers to.

    bumTomica
    Member

    @bumtomica

    It’s a result of a wpdb query.

    <div class="archive-lists">
    <?php $autor = $wpdb->get_results("SELECT meta_value AS autor FROM wp_posts LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE post_status = 'publish' AND meta_key = 'autor' GROUP BY meta_value ORDER BY meta_value") ?>
    <ol>
    <?php foreach( $autor as $autori ) : ?>
    <div class="autor">
    <li><a href="<?php echo esc_url( home_url( '/' ) ); ?>?s=<?php echo $autori->autor ?>"><?php echo $autori->autor ?></a></li>
    </div>
    <?php endforeach ?>
    </ol>
    </div>
    esmi
    Forum Moderator

    @esmi

    You might want to validate the $autori->autor value before outputting it to the screen but, apart from that, it all looks OK.

    bumTomica
    Member

    @bumtomica

    Okey, will do that, thanks for help! 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Create "template links" that are making search queries’ is closed to new replies.