Forums

api to search all the posts for a string (3 posts)

  1. dirkhaim
    Member
    Posted 5 years ago #

    I have a page to prevent hot linking (using htaccess), but I wish to include in it the link to the post that contains the data the user was directed to. So, what I need to do is search for REQUEST_URI and display the search results (links).

    So I need an API function that returns such links given a string to search. It's my first attempt at using the WordPress API, so I am quite in a need for help.

    Thanks.

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    Though it's not exactly documented in the codex anywhere, all the query_posts and WP_Query and get_posts and such functions should be able to take a parameter of "s=search_string" to return posts for that search string. So you should just be able to write a normal Loop with a "s=" parameter in the query to get search results.

    However, the search is pretty weak. It's probably not going to find stuff by you passing in a URI. Not unless the URI is actually in the content of your posts themselves.

  3. Andrew Ozz
    WordPress Dev
    Posted 5 years ago #

    If you are using permalinks, split the URI at the "/" and use only the last part as search query. Or perhaps install the http://www.zirona.com/software/wordpress-advanced-search/ plugin - fulltext search.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags