WordPress.org

Ready to get started?Download WordPress

Forums

Using wildcards in WP_Query with exclusions (6 posts)

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

    category_exclude=notnews*

    Thanks in advance

    Mike

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 4 years 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 4 years ago #

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

  4. s_ha_dum
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 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