• Resolved taghaboy

    (@taghaboy)


    Hello every one,
    I have a strange problem with my Custom Single Post for post type “single-park_auto.php”, I’m working in a child theme and i use this code generated with “Custom Post Type UI” :

    function cptui_register_my_cpts_park_auto() {
    
    	/**
    	 * Post Type: Park auto.
    	 */
    
    	$labels = array(
    		"name" => __( "Park auto", "custom-post-type-ui" ),
    		"singular_name" => __( "Park auto", "custom-post-type-ui" ),
    		"menu_name" => __( "Park auto", "custom-post-type-ui" ),
    		"add_new" => __( "Ajouter une voiture", "custom-post-type-ui" ),
    		"add_new_item" => __( "Ajouter une nouvelle voiture dans le Park Auto", "custom-post-type-ui" ),
    		"edit" => __( "Modifier", "custom-post-type-ui" ),
    		"edit_item" => __( "Modifier Park auto", "custom-post-type-ui" ),
    		"new_item" => __( "Nouveau voiture", "custom-post-type-ui" ),
    		"view" => __( "Aperçu", "custom-post-type-ui" ),
    		"view_item" => __( "Voire la voiture", "custom-post-type-ui" ),
    		"search_items" => __( "Cherche une voiture", "custom-post-type-ui" ),
    		"not_found" => __( "voiture introuvable", "custom-post-type-ui" ),
    		"not_found_in_trash" => __( "Voiture introuvable dans la Corbeille", "custom-post-type-ui" ),
    	);
    
    	$args = array(
    		"label" => __( "Park auto", "custom-post-type-ui" ),
    		"labels" => $labels,
    		"description" => "Ajouter ou modifier les voitures de votre park automobile",
    		"public" => true,
    		"publicly_queryable" => false,
    		"show_ui" => true,
    		"delete_with_user" => false,
    		"show_in_rest" => false,
    		"rest_base" => "",
    		"rest_controller_class" => "WP_REST_Posts_Controller",
    		"has_archive" => false,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"map_meta_cap" => true,
    		"hierarchical" => false,
    		"rewrite" => array( "slug" => "park_auto", "with_front" => true ),
    		"query_var" => true,
    		"menu_position" => 5,
    		"menu_icon" => "dashicons-cart",
    		"supports" => array( "title", "thumbnail" ),
    		"taxonomies" => array( "post_tag" ),
    	);
    
    	register_post_type( "park_auto", $args );
    }
    
    add_action( 'init', 'cptui_register_my_cpts_park_auto' );

    Inside the home page i have this code :

    <?php query_posts('post_type=park_auto'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div id="desc-cars-home">
    		<h2><a href="<?php the_permalink() ?>"><?php the_field ('classe');?> <?php the_field ('marque_et_model');?></a></h2>
    	</div>
    <?php endwhile; else : ?>
    <?php endif; 
    wp_reset_query();
    ?>

    So every time i click the link it redirect me to the some index or single.php , not to the page of product “single-park_auto.php”

    Have any one understand this issue?

    Thanks a lot.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Couple things that stand out to me:

    1. Publicly queryable is set to false, which is probably the biggest issue.
    2. The apparent need to use query_posts() at all in the single-park_auto.php file feels off because if it is actually showing a post from the right post type, that shouldn’t be needed.

    Perhaps as a quick test, add <?php echo get_post_type(); ?> somewhere and see what is coming out of it. particularly after the loop instantiation or at least after the query_posts() line

    Thread Starter taghaboy

    (@taghaboy)

    Wowwwww wowww wow
    I just set the “Publicly queryable” to “true” and all work,
    Thanks a lot
    Bravo

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Single Post for post type’ is closed to new replies.