WordPress.org

Ready to get started?Download WordPress

Forums

Dave's WordPress Live Search
[resolved] Dropdown shows unpublished drafts ! Gah! (6 posts)

  1. cadbloke
    Member
    Posted 3 years ago #

    Erm, had to disable this because the dropdown is showing unpublished drafts. I have Search Everything installed also but the search pages do not show any results from unpublished drafts, just the dropdown.

    Ruh Roh ...

    http://wordpress.org/extend/plugins/daves-wordpress-live-search/

  2. Dave Ross
    Member
    Plugin Author

    Posted 3 years ago #

    Well, the fix for that is pretty easy. In DavesWordPressLiveSearchResults.php, around line 60, there's this block of code:

    $wpQueryResults->query(array(
              's' => $_GET['s'],
              'showposts' => $maxResults,
              'post_type' => 'any',
            ));

    change it to:

    $wpQueryResults->query(array(
              's' => $_GET['s'],
              'showposts' => $maxResults,
              'post_type' => 'any',
              'post_status' => 'publish',
            ));

    (adding the line about post_status)

    All this seems unnecessary, though, as the docs for WP_Query/query_posts still say the default "post_status" is "publish", so drafts shouldn't be showing up. Have you updated this site to WordPress 3.1 already, or has this always been a problem?

    Ruh Roh indeed!

  3. Dave Ross
    Member
    Plugin Author

    Posted 3 years ago #

    Well that was some fun debugging there. Yes, the default is to only show "publish" posts UNLESS you're an admin.

    WP_Query checks for this by looking for a WP_ADMIN constant.

    WordPress doesn't technically support AJAX for non-admin functionality. It does kinda support it, but you have to register a few hooks and call admin-ajax.php. That file, being a file with "admin" in the name, residing in wp-admin, sets WP_ADMIN to true right at the top.

    So in order to make AJAX calls look only at "publish" content, I just need to add that "post_status" line and we should be good to go.

    I'll give it a try tomorrow after work.

    - Dave

  4. cadbloke
    Member
    Posted 3 years ago #

    Hi Dave

    It as working fine until either the upgrade to 3.1 or to the latest version of live search. I did them both at the same time so I can't tell you which one changed things.

    ... Stop the presses, I think you can blame me for this one. I checked it in Chrome, where I am logged in and the search results returned drafts. Then I thought I'd check it in a browser where I wasn't logged in so I used the Chrome Canary build. It runs as a separate process but it perhaps seems to share a cookie or 2 with the Mainstream version of Chrome. I'm not actually logged in in the Canary build. Odd

    It behaves as expected in Internet Exploder (not logged in).

    ... ah, dammit, This just gets silly now. I'm thinkong of blaming WordPress at this stage. I tried it in Firefox, not logged in, and got all the drafts. Cleared all my cookies, got all the drafts. I cleared the active logins & restarted the browser - same thing. The page is cached and is the same html in Canary, Fireofx and IE8 so I dunno why IE doesn't work the same (ok, I do but it's not a nice thing to say).

    I added the extra line from your first post and now it works fine, as expected. It shows me the drafts if I am logged in, which is kinda nice but was unexpected after I added the line to filter only published posts. I wonder if it's a regression bug in WordPress?

    I was testing it by searching for "yellow" at cadbloke.com. Let me know if it returns anything because, if it does, they're all unpublished drafts, probably riddled with swearing.

  5. Dave Ross
    Member
    Plugin Author

    Posted 3 years ago #

    Nothing comes up when I search "yellow", but I really need to start including a spinning wheel antialiased for dark backgrounds.

  6. cadbloke
    Member
    Posted 3 years ago #

    No "yellow" - good ! In that case, crisis over.

    Thanks again, Dave

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic