Using wildcards in WP_Query with exclusions (6 posts)

  1. michaelbolland
    Posted 6 years ago #

    Good morning all,

    Could anyone tell me if it's possible to include wildcards in WP_Query, for example: category=news*

    Also is it possible to have exclusions similar to this


    Thanks in advance


  2. No. Wildcards of that sort don't work, and there's no "category_exclude" parameter to begin with.

    You can use category__not_in for queries though, like so:

    // this excludes categories with ID's of 1, 2, and 3
    'category__not_in' => array(1,2,3),
  3. michaelbolland
    Posted 6 years ago #

    of that sort? is there another way? sorry the ID's could be anything

  4. s_ha_dum
    Posted 6 years ago #

    It is possible to directly alter the MySql query string via the posts_* filters. You really need to have a good grip on MySql syntax though.

  5. MichaelH
    Posted 6 years ago #

    Or could build an array of the category IDs you don't want with Function_Reference/get_categories, then use the format Otto suggested.

  6. michaelbolland
    Posted 6 years ago #

    but users will be adding categories later

    apljdi sounds like the best idea so far

Topic Closed

This topic has been closed to new replies.

About this Topic