The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Exclude special "Taxonomy" from a Custom Post Type... (13 posts)

  1. JoeyBottle
    Posted 6 years ago #

    Here I "query" the posts from the Custom Post Type "work".

    <?php query_posts($query_string . 'post_type=work&posts_per_page=4&meta_key=design'); ?>
        <?php $counter = 1; $num_posts = $wp_query->post_count; ?>
        <?php while (have_posts()) : the_post(); ?>
        <?php $extra_class = 'fourstarters'; if( $counter == $num_posts ) { $extra_class = 'fourstarterslast'; } ; $counter++; ?>
        <div <?php post_class($extra_class); ?> id="post-<?php the_ID(); ?>">
        <?php $image = get_post_meta($post->ID, "Image1", true); echo $image; ?>
        <h3>" title="<?php the_title() ?>"><?php the_title() ?></h3>
        <?php the_excerpt(__('')); ?>
        <?php endwhile;?>

    As you can see I gie the first three posts a different Class than the last one. Yeah now I want to EXCLUDE all the Posts which are in the Taxonomy named "frontcover" or with the ID=6 (it's the same). How can I do this ??

    Thank you already very much! Greatings

  2. chinmoy29
    Posted 6 years ago #

    replace the above line with
    <?php query_posts($query_string . 'post_type=work&posts_per_page=4&meta_key=design&cat=-6'); ?>

  3. JoeyBottle
    Posted 6 years ago #

    Yeah i tryd this, but it doesn't work...could it be that i forgot to registry the taxonomy somewhere ?? That's my functions.php code:

        function post_type_work() {
        array('label' => __('Work'),
        'singular_label' => __('work'),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'rewrite' => array("slug" => "work"),
        'supports' => array('title','editor','trackbacks','custom-fields','excerpt','thumbnail',),
        'menu_position' => 4
        register_taxonomy( 'workcat', 'work', array( 'hierarchical' => true, 'label' => __('Work-Category'), "rewrite" => true ) );
        register_taxonomy( 'worktype', 'work', array( 'hierarchical' => false, 'label' => __('Worktype'), "rewrite" => true, 'query_var' => 'worktype' ) );

    Could you - or anybody else - please check if I did everything right with this code and with the taxonomy ???

  4. JoeyBottle
    Posted 6 years ago #

    Meanwhile I also tried to to it with "category__not_in=6" and this also doesn't work...My new Taxonomy should normally work as an "Category" so I totally do not understand why "cat=-6" doesn't work here. I think that the solution for this problem could be really interesting for a lot of people in the future - I hope somebody could help!!!

  5. JoeyBottle
    Posted 6 years ago #

    I hope you don't get angry cause im pushing this threat but I work my ass of and don't come to any solution :( Please help me anybody!!! PLEAAAAASSEEEE

  6. Mark / t31os

    Posted 6 years ago #

    Why not use the existing categories taxonomy with your custom post type, you'll then be able to leverage the usage of the category exclusion parameters, which won't work if category is not the taxonomy being requested.. (which it's not).

    Alongside your custom taxonomies or in place of one, whichever, but in theory that should work around the problem (query_posts cannot exclude taxonomies that aren't built-in taxonomies, it's simply beyond the "current scope" of that function).

  7. JoeyBottle
    Posted 6 years ago #

    It can't be impossible! My PHP is not good enough to solve it by myself but here someone postet the posibilty how to show posts just from a specific Taxonomy, so it cant't be impossible to do the opposite: (in this case form the Custom Post type "people" and with the posts which have the taxonomy "will-smith":

    <?php query_posts( array( 'people' => 'will-smith', 'showposts' => 10 ) ); ?>

    I wish so hard that somebody will come across here who can solve it...

  8. sicdigital
    Posted 6 years ago #

    This is killing me, I'm trying to exclude a custom taxonomy from a query also!

  9. JoeyBottle
    Posted 6 years ago #

    Yeah it can't be impossible. Nobody know's the answer, still ??? Ah the exact form of the question is:

    "How to exclude a specific term of a custom taxonomy in a query?!"

  10. Mark / t31os

    Posted 6 years ago #

    "How to exclude a specific term of a custom taxonomy in a query?!"

    Use a custom written query..

    You can't do it using query_posts or a WP_Query object because the functionality is outside the scope of it's current capabilities, as i previously explained. I'm not sure how else to explain it, for custom taxonomies exclusions you'll have to look at writing a custom query (until such time the query class is extended to allow more fine grained taxonomy queries).

    If writing your own queries is an option, the following page provides all the information required.
    Generic query types.

  11. Creative Slice
    Posted 6 years ago #

    Here's how I got it working: 'location' is my custom taxonomy and $state is the slug of the location category chosen.

    $args=array('post_type' => 'page', 'location' => $state, 'showposts' => 99);
    $pages = get_posts($args);
    $pageids = array();
    foreach ($pages as $page) {
        $pageids[]= $page->ID;
    <?php wp_list_pages('title_li=&include='. implode(',', $pageids) .''); ?>
  12. web559
    Posted 5 years ago #

    @Mark/@t31os Is there any timeline for this? For WP_Query to allow exclusions for custom taxonomies?

  13. Mark / t31os

    Posted 5 years ago #

    It should be possible using the taxonomy query parameters now.

    See Otto's blog on advanced taxonomy queries here for some examples.

Topic Closed

This topic has been closed to new replies.

About this Topic