WordPress.org

Ready to get started?Download WordPress

Forums

Related posts and Search in sidebar (2 posts)

  1. dadvan
    Member
    Posted 1 year ago #

    Hello,

    I am trying to figure out how I can display related posts (by category/categories and/or tags) maybe top 5 but have a link to display all in a page. Also in need to be able to search within these related post only and not entire site.

    The initial related posts (top 5) will be in the side bar with a search box/form above it then a link to view all related post below the list of 5 related posts.

    The page that lists all the related posts will have a search box.

    I have found several code snippets but they are all for much earlier versions. I can post what I found if it would be helpful.

  2. dadvan
    Member
    Posted 1 year ago #

    I found this code which I put in functions.php

    function wp_search_form($form) {
    global $wp_query;
    
    $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
    <input type="hidden" name="cat" value="'. $wp_query->get_queried_object_id() .'" />
    <input type="text" class="search_input" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
    <input type="submit" alt="Search" class="greybutton float_right" value="Search" />
    
    </div>
    </form>';
    return $form;
    }

    And I put this in my page template: <?php wp_search_form(); ?>

    But the place where I am expecting to see the form show up is comping up blank.

    Am missing something or is the code I found no good?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.