Permintaan WP – Tidak bisa mendapatkan posting dengan taksonomi tertentu

Saya tidak bisa mendapatkan kiriman khusus saya dengan taksonomi tertentu. Ini kode saya di functions.php :

    function portalp_custom_post_type_realisations() {
    $labels = array(
        'name'                  => _x("Réalisations", 'Post type general name', 'textdomain'),
        'singular_name'         => _x("Réalisation", 'Post type singular name', 'textdomain'),
        'menu_name'             => _x("Réalisations", 'Admin Menu text', 'textdomain'),
        'add_new'               => __("Ajouter", 'textdomain'),
        'add_new_item'          => __("Ajouter une réalisation", 'textdomain'),
        'new_item'              => __("Nouvelle réalisation", 'textdomain'),
        'edit_item'             => __("Modifier une réalisation ", 'textdomain'),
        'view_item'             => __("Voir la réalisation", 'textdomain'),
        'all_items'             => __("Toutes les réalisations", 'textdomain'),
        'search_items'          => __("Rechercher des réalisations", 'textdomain'),
        'not_found'             => __("Aucune réalisation trouvée.", 'textdomain'),
        'not_found_in_trash'    => __("Aucune réalisation trouvée dans la corbeille.", 'textdomain'),
        'featured_image'        => _x("Image à la une de la réalisation", 'Overrides the “Featured Image” phrase for this post type.                                        Added in 4.3', 'textdomain'),
        'set_featured_image'    => _x('Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3',                                       'textdomain'),
        'remove_featured_image' => _x('Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in                                       4.3', 'textdomain'),
        'use_featured_image'    => _x('Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in                                       4.3', 'textdomain'),
        'archives'              => _x("Toutes les réalisations", 'The post type archive label used in nav menus. Default “Post                                            Archives”. Added in 4.4', 'textdomain'),
        'insert_into_item'      => _x("Insérer dans la réalisation", 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'textdomain'),
        'uploaded_to_this_item' => _x('Uploaded to this book', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'textdomain'),
        'filter_items_list'     => _x('Filter books list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'textdomain'),
        'items_list_navigation' => _x('Books list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'textdomain'),
        'items_list'            => _x('Books list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'textdomain'),
    );

    $args = array(
        'description'           => __("Les réalisations de Portalp"),
        'labels'                => $labels,
        'supports'              => array('title', 'revisions', 'custom-fields', 'thumbnail', 'post-formats'),
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'show_in_rest'          => true,
        'menu_position'         => 4,
        'menu_icon'             => 'dashicons-format-gallery',
        'map_meta_cap'          => true,
    );

    // Enregistrement du Custom Post Type
    register_post_type('realisations', $args);}

add_action('init', 'portalp_custom_post_type_realisations');
    /**

 * Déclaration des taxonomies personnalisées pour Portalp
 */

function portalp_custom_taxonomies() {
    
    // Déclaration de la taxonomie "Transports"

    $labels_transports = array(
        'name'                          => _x( 'Transports', 'taxonomy general name'),
        'singular_name'                 => _x( 'Transport', 'taxonomy singular name'),
        'search_items'                  => __( 'Chercher un transport'),
        'all_items'                     => __( 'Tous les transports'),
        'edit_item'                     => __( 'Editer le transport'),
        'update_item'                   => __( 'Mettre à jour le transport'),
        'add_new_item'                  => __( 'Ajouter un nouveau transport'),
        'new_item_name'                 => __( 'Valeur du nouveau transport'),
        'menu_name'         => __( 'Transports'),
    );

    $args_transports = array(
        'description'       => 'Type de transport de la réalisation',
        'public'            => false,
        'hierarchical'      => true,
        'labels'            => $labels_transports,
        'show_ui'           => true,
        'show_in_rest'      => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'transports' ),
    );

    register_taxonomy('transports', array('realisations'), $args_transports);
    
    
//     // Déclaration de la taxonomie "Solutions"

    $labels_solutions = array(
        'name'                          => _x( 'Solutions', 'taxonomy general name'),
        'singular_name'                 => _x( 'Solution', 'taxonomy singular name'),
        'search_items'                  => __( 'Chercher une solution'),
        'all_items'                     => __( 'Toutes les solutions'),
        'edit_item'                     => __( 'Editer la solution'),
        'update_item'                   => __( 'Mettre à jour la solution'),
        'add_new_item'                  => __( 'Ajouter une nouvelle solution'),
        'new_item_name'                 => __( 'Valeur de la nouvelle solution'),
        'menu_name'         => __( 'Solutions'),
    );

    $args_solutions = array(
        'description'       => 'Catégories de produits installés sur les chantiers',
        'public'            => false,
        'hierarchical'      => true,
        'labels'            => $labels_solutions,
        'show_ui'           => true,
        'show_in_rest'      => true,
        'show_admin_column' => true,
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'solutions' ),
    );

    register_taxonomy('solutions', 'realisations', $args_solutions);
    add_action('init', 'portalp_custom_taxonomies');
    $args = array(
        'post_type' => "realisations",
        'tax_query' => array(
            array(
                'taxonomy'  => 'transports',
                'field' => 'slug',
                'terms' => "mini-metro",
            ),
        ),
    );
    $query = new WP_Query($args);
    ?>
    <pre>
        <?php
    var_dump($query);
        ?>
        </pre>
        <?php
    die();

var_dump berfungsi dengan baik ketika saya tidak menentukan parameter kueri pajak. Tetapi ketika saya menyetel tax_query itu tidak berfungsi lagi. Apakah Anda tahu mengapa kode ini tidak berfungsi?

Terima kasih sebelumnya.

Leave a Reply

Your email address will not be published. Required fields are marked *