• Hello. Experts.

    I want to show the whole post results that are searched by keywords in the post title at the bottom of the post.
    For example, if you write a post about the iPhone, you will see posts about the iPhone at the bottom of the post.
    It’s easy to show results sorted by tag or category, but I do not know how to do this.
    Once I have found the keyword, I want to use it to search the whole post and show the result bottom of the post.

    I need your help.
    Please recommend a solution.

    Regards
    gungs

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Are you thinking these results will appear below all single post pages? Only certain ones? Anywhere else?

    For all single posts, you can modify the theme’s single post template to show all results. By default, a WP search query will search titles and content for search terms. Multiple keywords all need to be found. If that is satisfactory, you would create a new WP_Query object with appropriate arguments, then run a secondary loop to output the results.

    Some processing of the title would be appropriate to remove unsuitable search terms like a, the, of, to, etc. These terms could be in an array. The title could be exploded, then looped through to decide if each term is in the exclusion array. If it is, unset the array item. When finished, implode the search terms back into a single string for use as the ‘s’ argument in WP_Query.

    Thread Starter gungs

    (@gungs)

    Thankyou @bcworkz

    $query = new WP_Query( array( ‘s’ => ‘keyword’ ) );

    I can get a hint to solve problem thanks to you ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to insert search results into posts’ is closed to new replies.