Hi Neroth
There is no archive page for the taxonomy itself, only archive pages for the terms of a taxonomy.
You can create a “Page” with the title (slug) “documents” and do a custom query for the taxonomy posts in the page template itself.
https://codex.wordpress.org/Function_Reference/WP_Query
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/
To query all posts in a taxonomy put this in your (child) theme’s functions.php file
// Add a new public query variable: taxonomy_archive
add_filter ( 'query_vars', 'add_taxonomy_query_var' );
function add_taxonomy_query_var( $query_vars ) {
$query_vars['taxonomy_archive'] = '';
return $query_vars;
}
add_action( 'posts_clauses', 'taxonomy_archive_clauses', 10, 2 );
function taxonomy_archive_clauses( $pieces, $query ) {
global $wpdb;
$archive_query = $query->get( 'taxonomy_archive' );
// Check if it's a query for a taxonomy archive
if ( !empty( $archive_query ) ) {
// Query for the taxonomy provided in the taxonomy_archive query variable
$pieces['join'] .= " INNER JOIN {$wpdb->term_relationships} tr_tarchive ON ($wpdb->posts.ID = tr_tarchive.object_id)";
$pieces['join'] .= " INNER JOIN {$wpdb->term_taxonomy} tt_tarchive ON (tr_tarchive.term_taxonomy_id = tt_tarchive.term_taxonomy_id)";
$pieces['where'] .= $wpdb->prepare( " AND tt_tarchive.taxonomy = %s", $archive_query );
}
return $pieces;
}
With this new code you can now use the new query var “taxonomy_archive” in your custom query inside a page template file.
Example of the query in a simplified page template file
<?php
$args = array(
'post_type' => array( 'document' ),
'taxonomy_archive' => 'documents',
);
// the query
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<!-- Loop stuff here -->
<?php endwhile; ?>
<!-- end of the loop -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
btw:
consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.
Thread Starter
Neroth
(@neroth)
Hi keesiemeijer !
I thought I made a mistake !
I will use your code, thanks for your help and work !
Have a good day !
Parse error: syntax error, unexpected ‘<‘ in C:\xampp\htdocs\my files\wordpress\wp-includes\taxonomy.php on line 387
what i do?