• query_posts('post_type=For_Sale&order=ASC&nopaging=true&cat=-24');

    I am using the above query to return every post with the custom type of ‘For_Sale’. I need to exclude category 24, but adding ‘cat=-24’ has no affect. What am I missing?

    This is my code for the custom type and taxonomy, just in case I’ve made a mistake here:

    //Add For Sale custom type and associated taxonomies
    
    add_action('init', 'tap_forsale_custom_type');
    function tap_forsale_custom_type()
    {
      $labels = array(
        'name' => _x('For Sale', 'post type general name'),
        'singular_name' => _x('For_Sale', 'post type singular name'),
        'add_new' => _x('Add Post', 'For_Sale'),
        'add_new_item' => __('Add For Sale Post'),
        'edit_item' => __('Edit For Sale Post'),
        'new_item' => __('New For Sale Post'),
        'view_item' => __('View For Sale Post'),
        'search_items' => __('Search For Sale Posts'),
        'not_found' =>  __('No For Sale Posts found'),
        'not_found_in_trash' => __('No For Sale Posts found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => 5,
        'supports' => array('title','editor','revisions','custom-fields')
    
      );
      register_post_type('For_Sale',$args);
    }
    
    add_action( 'init', 'create_forsale_taxonomies', 0 );
    
    function create_forsale_taxonomies()
    {
      // Add new taxonomy, make it hierarchical (like categories)
      $labels = array(
        'name' => _x( 'Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Categories', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search "For Sale" Categories' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit  "For Sale" Category' ),
        'update_item' => __( 'Update "For Sale" Category' ),
        'add_new_item' => __( 'Add New "For Sale" Category' ),
        'new_item_name' => __( 'New "For Sale" Category' ),
      ); 	
    
      register_taxonomy('fs_categories',array('For_Sale'), array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'For Sale' ),
      ));
    };
Viewing 1 replies (of 1 total)
  • Thread Starter planky

    (@planky)

    Found this:

    (query_posts cannot exclude taxonomies that aren’t built-in taxonomies, it’s simply beyond the “current scope” of that function).

    So it looks like its not possible with query_posts

Viewing 1 replies (of 1 total)
  • The topic ‘Exclude posts in certain categories for custom post type’ is closed to new replies.