I\'m new to WordPress (and to code), having just started my classes. I am working on a project with a few students and can\'t find a way to call my Custom Post Type.
I tried several solutions from StackExchange, but I can\'t really find a solution for my problems.
Problem 1 : my custom Post type doesn\'t have the right name in my back office
Here\'s how I coded my custom post type :
function custom_post_type_bateau() {
$labels = array(
\'name\' => \'Bateaux\',
\'singular_name\' => \'Bateau\',
\'menu_name\' => \'Bateaux\',
\'name_admin_bar\' => \'Ajouter\',
\'add_new\' => \'Nouveau bateau\',
\'add_new_item\' => \'Ajouter un bateau\',
\'edit_item\' => \'Modifier un bateau\',
\'view_item\' => \'Consulter un bateau\',
\'search_items\' => \'Chercher un bateau\',
\'parent_item_colon\' => \'Bateaux parents\',
\'not_found\' => \'Aucun bateau n\\\'a été trouvé\',
\'not_found_in_trash\' => \'Aucun bateau n\\\'a été trouvé dans la corbeille\'
);
$args = array(
\'labels\' => \'Bateau\',
\'description\' => \'Un bateau de SailingLoc\',
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'bateau\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'menu_icon\' =>\'dashicons-paperclip\',
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'bateau\', $args );
}
I called it in my functions.php :
add_action(\'init\', \'initialisation\');
function initialisation(){
//activation des menus dans le backoffice
register_nav_menus();
//creation d\'un custom post type bateau
custom_post_type_bateau();
// activation des images à l\'affiche
add_theme_support(\'post-thumbnails\');
}
Problem is that the name displayed in my back-office isn\'t "Bateaux" but "Articles".
Problem 2 : I can\'t call the post-type bateau
So I made a page to display my post-types. I called it with this WP Query :
<?php
$query = new WP_Query([
\'post_type\' => \'bateau\',
\'posts_per_page\'=>15
]);
?>
<?php
$the_query = new WP_Query();
$the_query->query($query);
; ?>
<div class="gp3">
<?php /*BOUCLE QUI RECUPERE LES DERNIERS POSTS*/
if ( $the_query->have_posts() ) :
$cpt = 0;
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<div class="col-4">
<div class="fiche-bateau">
<div class="image-bateau">
<div class="product-thumbnails image-responsive"><?php the_post_thumbnail(); ?>
</div>
</div>
<div class="product-title"><?php the_title(\'<h3>\', \'</h3>\'); ?>
</div>
</div>
</div>
<?php
$cpt ++;
if ($cpt%3 == 0) :
?>
</div>
<div class="gp3">
<?php endif; ?>
<?php endwhile; else : ?>
<p>Rien à afficher</p>
<?php endif; ?>
</div>
The variable $query should link to the custom post-type \'bateau\' but doesn\'t. Instead I get the blog posts.
Could you help me pretty please ?