my site looks like:

Page-1 (page.php)
... Subpage-1 (custom-collection.php; Custom Post Type)
...... Filtering Output-Post (custom-collection-single.php)

When I open the filtering output-post by using /%postname% for permalinks I get 404 error page.

Some code:


<?php $args = array( 'post_type' => 'weine', 'posts_per_page' => -1, 'orderby' => 'rand' );

// ============================= WHITEWINE ===============================
if( is_page('147') ) { 

$args = array(
    'tax_query' => array(
            'taxonomy' => 'sorte',
            'field' => 'slug',
            'terms' => array('weisswein')

// ============================= REDWINE ===============================


// =========================== All WINES ==================================
else {}

$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <a class="item" rel="wine" href="<?php the_permalink(); ?>" >
    <?php the_post_thumbnail('wine-flow', array('class' => 'content')); ?>
    <!-- <div class="label">Slider Label</div> -->

<?php endwhile; ?>


<?php get_template_part( 'loop', 'single-empty' ); ?>

    echo '<div class="wein-bottle-thumb">';

            echo '...';


The Loop (loop-single-empty.php)

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<?php endwhile; ?>

I try to added this to my functions.php

add_action('admin_init', 'flush_rewrite_rules');

When I use standard permalinks everything works fine for me.
.htaccess: <IfModule mod_rewrite.c> ... is active

Thanks for your help.

1 Answer 1


Your setup is all over the place. Lets refer to the visual overview here:


enter image description here

Your page is going to use the page.php template.

Your custom post type weine will use single-weine.php

Your custom taxonomy sorte ( probably not the best name as it might clash ) will use the template taxonomy-sorte.php

So we can expect by default to have a weine post with the title "example" to live at:


and the sorte taxonomy term 'examplesorte' will have its archive at:


What I expect you're trying to do is change it so that there is no /weine/, or you think that by using postname that it will change the link of 'weine' posts. This is incorrect, and while there is code out there that may change this, I strongly recommend against this as it introduces dangerous permalink clashes. It's also better if you use the weine URL structure to your advantage.

e.g. I would recommend modifying the rewrite base of the sorte taxonomy to use weine/sorte as it's base, giving you URLs such as:


A Note On Flushing Rewrites

You need to flush them when your custom post types and taxonomies change, but never do it on admin_init or init. Regenerating rewrite rules is slow and expensive, and by putting it on those hooks, you're massively slowing down your site, and introducing potential bugs and problems.

I would also kill trying to set custom post types parents as that of a normal page. Use the slug in the rewrite base but go no further than that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.