WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP_QUERY category_name (4 posts)

  1. fabrix
    Member
    Posted 4 years ago #

    Hi all,
    this is my question: I wanna exclude a category name from a query result:
    cat=-3 WORKS
    category_name=-aname DOESN'T WORK

    I need to use a name instead of a number, there is a way to do it?

    Tnx in advance

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    See the information here.
    http://codex.wordpress.org/Function_Reference/query_posts#Category_Parameters

    You need to use category__not_in.

  3. MichaelH
    Member
    Posted 4 years ago #

    $cat_id = get_cat_ID('category name here');
    $args=array(
      'category__not_in' => array($cat_id),
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
  4. fabrix
    Member
    Posted 4 years ago #

    Hi, $cat_id = get_cat_ID('category name here') is what I'm looking for!
    many tanks

Topic Closed

This topic has been closed to new replies.

About this Topic