• 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="https://simplynote.me/?s=<?php echo $autori->autor ?>"><?php echo $autori->autor ?></a>

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • <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.

    Thread Starter bumTomica

    (@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>

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

    Thread Starter bumTomica

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