WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Want to customize search results to show summary of posts (5 posts)

  1. cmortazavi13
    Member
    Posted 3 years ago #

    Hi i am kinda new and i was hoping i could get some help with a small issue. I am using WP custom fields search to have users search through my post and i want the results of my search to be displayed in a certain way. Right now the entire posts are being displayed and i only want a list of the post titles to be displayed along with a one sentence summary of the posts. I do not want the summary to be the first 50-something words of the post i would like to have a one sentence summary of the post that is independent of the post content (even thought it is summarizing it). Any help you guys could give me would be much appreciated.

  2. stvwlf
    Member
    Posted 3 years ago #

    If you are not using post excerpts for any other purpose, you could use the built in WordPress manual excerpt feature to store your one sentence post summaries, and then change the search page to display the post excerpt instead of the full post content.

    1) Nowadays the post excerpt box is hidden by default. On the Post edit page, click screen options in the upper right corner and put a check in Excerpts. That reveals the excerpts entry box. When a manual excerpt exists on a post WordPress will display that rather than the default first 55 words of the post, when an excerpt is being displayed.

    2) If you want to have the Visual Editor on the excerpts box (its optional - you can use HTML tags in the box without the editor) install this plugin
    http://wordpress.org/extend/plugins/tinymce-excerpt/

    3) Then you have to edit your search results template and replace
    the_content() with the_excerpt(); There may be code between the parentheses of the_content() - that's fine. Its not needed with the_excerpt(). If you are not too familiar with editing code the best bet is make a backup copy of the search template before you change anything so if you run into issues you can go back to how it was before you changed it.

    Here's an old article about manual excerpts.
    http://op111.net/67/
    You really don't need an additional plugin to do this (other than possibly the visual editor plugin I mentioned).

    This should get you started.

  3. cmortazavi13
    Member
    Posted 3 years ago #

    Thank you so much this was a huge help and this was exactly what i was looking for. I didn't even know about the screen options and how i could add different criteria for my posts. I was also wondering how i could display my custom fields and have my posts ordered by those custom fields in the search results. SO for example i want to add a custom field where the key is "author" and the value= the authors name and this would be viewable to the user on search results pages and on the post itself and i want to add another custom field where the key is "article" and the value is a number and the posts are ordered by the article number in the search results page from least to greatest. Any help you could give me would be great because as of right now I'm having a hard time even displaying my custom fields on my posts or my search results page.

  4. stvwlf
    Member
    Posted 3 years ago #

    What you wish to do requires PHP coding changes to alter the default WordPress query that is run to produce the search results.

    I've not used this plugin but it might let you do what you want
    http://wordpress.org/extend/plugins/query-posts/

    http://justintadlock.com/archives/2009/03/15/query-posts-widget-wordpress-plugin

    If not you need some code changes. The raw instructions are here:
    http://codex.wordpress.org/Template_Tags/query_posts

    http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    If you have little experience with PHP coding you may not find the raw instructions easy to follow. Basically you have to override the default query parameters before the WordPress loop on the search page.

    What you want is not especially involved for someone who knows their way around WordPress. It would be a bit tricky as a learning project. It sounds like you need a custom search form too because you need a way for people to indicate how they want their search results ordered. Then that order has to be passed to the search results page so its included in the query that runs the search.

    I can't recall any articles describing creating a process like that. You could Google for WordPress customize search results as a starting place

  5. cmortazavi13
    Member
    Posted 3 years ago #

    thank you very much for your help.

Topic Closed

This topic has been closed to new replies.

About this Topic