Forums

Using wildcards in WP_Query with exclusions (6 posts)

  1. michaelbolland
    Member
    Posted 2 months 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

    category_exclude=notnews*

    Thanks in advance

    Mike

  2. Otto42
    Moderator
    Posted 2 months ago #

    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
    query_posts(array(
    'category__not_in' => array(1,2,3),
    ));
  3. michaelbolland
    Member
    Posted 2 months ago #

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

  4. apljdi
    Member
    Posted 2 months 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
    moderator
    Posted 2 months 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
    Member
    Posted 1 month ago #

    but users will be adding categories later

    apljdi sounds like the best idea so far

Reply

You must log in to post.

About this Topic