Support » Plugins » Hacks » search only logged in user's posts

Viewing 11 replies - 1 through 11 (of 11 total)
  • If you query your page with the author ID as part of the search query string it will filter by author…


    You can’t have two forms, with two sets of inputs with the same IDs and names, but the search won’t pass parameters correctly with differing IDs. So what i’d suggest is adding a checkbox to your search form that holds the value of the current user’s ID, when it’s checked, the search will pass this along in the query string(just make sure you give the input an ID and name of author).

    NOTE: You can use author_name in place of author if you prefer the query string to contain the username in place of the ID.

    Hi Mark,

    Thanks for your reply!

    I had already previously tried /?s=search-term&author=1 when i had two forms and it didn’t work. And then i read your post, and (hopefully correctly!) saw that its difficult (impossible?) to have two search forms, and so much easier to get rid of the 2nd and add a checkbox (which adds author id) to the 1st (and now only) search form.

    So i got rid of my 2nd search form, but still the /?s=search-term&author=1 ending isn’t working!

    On top of this i am struggling to work out what value i need to insert the author’s id automatically through the checkbox. I thought i could just use %userid% but this doesn’t work. i tried playing around with stuff i found through trawling the forums, but i don’t really know what i am doing! Any pointers in the right direction would be great!

    /?s=search-term&author=1 won’t find anything unless a post has search-term in the title or content, use something generic to make sure you get matches..



    And see if you then get results.. (the checkbox will be of little use if the search requests aren’t working with the author parameters).

    (i wasn’t actually searching for “search-term” but rather replaced it with a search term.)

    nothing generic seems to apply the author filter… for example i try


    to search for all posts by the author with id=1 which include the word “horse”. and i get simply all the posts that include the word “horse”, without the author filter being applied.

    i tried also with author names and still nothing.

    is there obvious i am missing? something i haven’t done?

    PS: just so you know, in case it makes any difference, i am using the journalist v1.3 theme which doesn’t have a searchform.php (or search.php) and so i am editing the search form in the general-template.php found in the wp-includes folder.

    There’s no need to be making changes to core WordPress files, the best approach would be to copy one of your theme’s template files and naming it search.php(choose which ever suits how you want search pages to appear, archive.php may be an obvious choice, but choose at your leisrue), so your theme has a search template, it may even fix your problem with not being able to request searches by author. I have an idea why the requests don’t work, but you should be able to resolve that by creating a search template for your theme..

    hi. i have put now a search.php template in my theme. (i just simply copied then renamed page.php)

    but still the author filter doesn’t work…

    any ideas about why?
    is there something i am going to have to do involving php code?

    Might i suggest switching to the default theme, just for a couple of minutes and seeing if searches (with and without author parameters) are working, if they do your problem is specific to how the theme is handling search requests..(be sure to test with plugins disabled to).

    Is this the theme you’re using?

    Hi, no i am using The Journalist version 1.3 (this one

    OK so i went through disabling each plugin and figured out what the problem is.. “WPSearch” the plugin which (is meant to!) enhance your searching. It works really well in some respects.. for example if you search for “war” it doesn’t just pick out any word which involves the letters “w-a-r” togehter, as the simple search does. you also get more control over what kind of content it searches etc.. BUT obviously there is some kind of problem with the author filtering.

    i’ve looked on the web but can’t find any report of this problem

    do you think i should just try out some other search plug ins?
    or can you suggest a little fix i can do to it ?… (because otherwise i am very pleased with how it performs)


    So the search is working correctly with the search plugin is disabled? If that’s the case i’d suggest creating a support topic specific to your problems with the plugin(the plugin author can better advise on solutions to problems with his/her code).

    yes exactly, seems to be something to do with the plugin. i will create a new support topic.
    thanks for all your help mark!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘search only logged in user's posts’ is closed to new replies.