• Resolved FMarion

    (@fmarion)


    I am attempting to use either query_posts() or WP_Query() to return the results of a custom taxonomy. I pass an array of slugs to the query based on a form’s request. (Basically, this is a custom search function). I want that when no slugs are passed to to my queries, that the query returns 0 results. By default, it appears to return all results.

    This is what I’m currently doing:

    Displaying custom taxonomies based on form request
    http://pastebin.com/YxkNAs78

    What am I missing to be able to have the query return zero results if no slug was passed to it?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Maybe check if there is a $_REQUEST

    if(isset($_REQUEST)) {
    // do your query and loop
    }

    and even better check if slug is in the $_REQUEST.
    depending on your form:

    if(isset($_REQUEST['slug']) && $_REQUEST['slug']) {
    // do your query and loop
    } else {
    echo "Y U No choose terms?";
    }

    Thread Starter FMarion

    (@fmarion)

    Thank you, the latter choice was helpful. I’ll get the hang of PHP sooner or later 🙂

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad I could help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to stop query_posts or WP_query from returning results if no criteria?’ is closed to new replies.