WordPress.org

Ready to get started?Download WordPress

Forums

Search on Page Slug (4 posts)

  1. dadvan
    Member
    Posted 1 year ago #

    Hello,

    How can I have a search form that queries only post that has a tag that matches the current page's page slug?

  2. dadvan
    Member
    Posted 1 year ago #

    I am able to search within the tag group with this:

    <form method="get" id="search form" action="/">
    <div>
    <input type="text" value="" name="s" id="s" />
    <input type="hidden" value="consulting" name="tag" id="post_tag" />
    <input type="submit" id="search_submit" name="Search" value="Search"/>
    </div>
    </form>

    How can I pull in the page slug as the value in the hidden field?

  3. dadvan
    Member
    Posted 1 year ago #

    OK, So i inputted this in the value and now it will search in a tag that matches the page slug:

    <?php echo $post->post_name; ?>

    Hope this helps someone!

  4. danielnichols
    Member
    Posted 1 year ago #

    Hiya,

    I'm also trying to create a search form that finds and highlights the results by only looking at the current page.

    thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic