Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Dana Ross

    (@csixty4)

    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!

    Plugin Author Dana Ross

    (@csixty4)

    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

    Thread Starter cadbloke

    (@cadbloke)

    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.

    Plugin Author Dana Ross

    (@csixty4)

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

    Thread Starter cadbloke

    (@cadbloke)

    No “yellow” – good ! In that case, crisis over.

    Thanks again, Dave

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Dave's WordPress Live Search] Dropdown shows unpublished drafts ! Gah!’ is closed to new replies.