WordPress.org

Ready to get started?Download WordPress

Forums

Create "template links" that are making search queries (5 posts)

  1. bumTomica
    Member
    Posted 1 year ago #

    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!

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    <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.

  3. bumTomica
    Member
    Posted 1 year ago #

    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>
  4. esmi
    Forum Moderator
    Posted 1 year ago #

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

  5. bumTomica
    Member
    Posted 1 year ago #

    Okey, will do that, thanks for help! :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags