• 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(__('')); ?>
    
        </div>
    
        <?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

Viewing 12 replies - 1 through 12 (of 12 total)
  • replace the above line with
    <?php query_posts($query_string . 'post_type=work&posts_per_page=4&meta_key=design&cat=-6'); ?>

    Thread Starter joeybottle

    (@joeybottle)

    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:

    <?php
        function post_type_work() {
        register_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' ) );
        }
        add_action('init','post_type_work');

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

    Thread Starter joeybottle

    (@joeybottle)

    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!!!

    Thread Starter joeybottle

    (@joeybottle)

    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

    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).

    Thread Starter joeybottle

    (@joeybottle)

    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…

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

    Thread Starter joeybottle

    (@joeybottle)

    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?!”

    “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.
    https://codex.www.ads-software.com/Function_Reference/wpdb_Class
    Generic query types.
    https://codex.www.ads-software.com/Function_Reference/wpdb_Class#SELECT_Generic_Results

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

    <?php
    $args=array('post_type' => 'page', 'location' => $state, 'showposts' => 99);
    $pages = get_posts($args);
    $pageids = array();
    foreach ($pages as $page) {
        $pageids[]= $page->ID;
    }
    ?>
    
    <ul>
    <?php wp_list_pages('title_li=&include='. implode(',', $pageids) .''); ?>
    </ul>
    </div>

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

    It should be possible using the taxonomy query parameters now.

    See Otto’s blog on advanced taxonomy queries here for some examples.
    https://ottopress.com/2010/wordpress-3-1-advanced-taxonomy-queries/

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Exclude special "Taxonomy" from a Custom Post Type…’ is closed to new replies.