How to get first post in a category of a custom taxonomy

tax_query takes an array of tax query arguments arrays (it takes an array of arrays) but you are using only single array. The correct code is as following.

<ul class="product-categories">
<?php
        $categories = get_terms(
            array(
                'produkter'
            ),
            array(
                'hide_empty' => false,
            )
        );

        foreach( $categories AS $cat )
        {
           $taxonomy = new WP_Query( array( 'posts_per_page' => 1, 'post_type' =>'book', 'tax_query' => array( array('taxonomy' => 'produkter','field' => 'slug', 'terms' => $cat->slug ) )) );
            while ( $taxonomy->have_posts() )
            {
                $taxonomy->the_post();
            ?>

                <li class="produkter">
                    <div class="product-image">
                        <a href="https://wordpress.stackexchange.com/questions/95262/<?php bloginfo("wpurl' ); ?>/produkt/">
                            <?php the_post_thumbnail( "product-small" ); ?>
                        </a>
                    </div>

                    <a class="product-title" href="https://wordpress.stackexchange.com/questions/95262/<?php bloginfo("wpurl' ); ?>/produkt/"><?php echo $cat->name ?></a>
                </li>

            <?php
            }
        }
?>
</ul>

For More information visit this page.

Leave a Comment