The issue with the labels in problem 1 is that you haven’t passed the labels to register_post_type()
. You’ve defined the labels in the $labels
variable, but this is what you passed to register_post_type()
:
$args = array(
'labels' => 'Bateau',
// ...
);
register_post_type( 'bateau', $args );
You need to pass the $labels
array:
$args = array(
'labels' => $labels,
// ...
);
register_post_type( 'bateau', $args );
For problem 2, your problem is that you’re trying to pass a WP_Query
instance to another WP_Query
. $query
needs to just be the array of arguments, but you’ve passed an entire WP_Query
object:
<?php
$query = new WP_Query([
'post_type' => 'bateau',
'posts_per_page'=>15
]);
?>
<?php
$the_query = new WP_Query();
$the_query->query($query);
; ?>
That needs to be just:
<?php
$the_query = new WP_Query ( [
'post_type' => 'bateau',
'posts_per_page' =>15
] );
?>
But, you shouldn’t need to create a page or template like this at all. In your post type registration you have:
'has_archive' => true,
This means that an archive (list) page for your post type is created automatically at http://example.com/bateau/
. This is what the “Voir les articles” link in the admin bar in your screenshot is linked to. If this isn’t working, make sure to go to Settings > Permalinks to flush your permalinks (visiting the settings page is enough), and make sure that your theme’s templates are properly using the main loop:
if ( have_posts() ) :
while ( have_posts() ) : the_post();
endwhile;
endif;
Note the lack of $the_query->
and any new WP_Query()
.