I found an even better way to do this.
When you navigate to /type/standard
, WordPress does try to perform a query on post_format = post-format-standard
, but that just doesn’t return anything, because there is no post-format-standard
.
So you can add a pre_get_posts
action to perform this query if WP is “trying” to get standard posts this way:
function standard_posts( $query ) {
if ( $query->get( 'post_format' ) === 'post-format-standard' ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => 'post_format',
'operator' => 'NOT EXISTS'
)
) );
$query->set( 'post_format', NULL );
}
}
add_action( 'pre_get_posts', 'standard_posts' );
The output of the_archive_title
would just be Archives
, so you can fix this in this slightly hacky way:
function standard_posts_archive_title( $title ) {
if ( is_tax() && $title === 'Archives' ) {
return __( 'Standard Posts' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'standard_posts_archive_title', 10, 1 );
-
This reply was modified 7 months, 2 weeks ago by Jay.
-
This reply was modified 7 months, 2 weeks ago by bcworkz. Reason: 'query' changed to 'get' in action hook