WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to stop query_posts or WP_query from returning results if no criteria? (4 posts)

  1. FMarion
    Member
    Posted 2 years ago #

    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

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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?";
    }
  3. FMarion
    Member
    Posted 2 years ago #

    Thank you, the latter choice was helpful. I'll get the hang of PHP sooner or later :)

  4. keesiemeijer
    moderator
    Posted 2 years ago #

    You're welcome. Glad I could help.

Topic Closed

This topic has been closed to new replies.

About this Topic