Hallo WP Gemeinde, ich habe einen Custom Post Type und eine dazugehörige Custom Kategorie registriert. Ich kann Beiträge erstellen und auch die Kategorie auswählen. Leider klappt das mit der Ausgabe nicht. Alles suchen und probieren hat mich nicht weitergebracht.
Code
// Custom Post Type Ads
function mtxads_custom_post_type() {
register_post_type('mtx-ads',
array(
'labels' => array(
'name' => __('Anzeige', 'mtx' )
'singular_name' => __('Anzeigen', 'mtx' )
...
),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'capability_type' => 'post',
'publicly_queryable' => true,
'exclude_from_search' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions' ),
'menu_icon' => 'dashicons-list-view',
'has_archive' => true,
'can_export' => false,
'rewrite' => array('slug' => 'mtx-ads' ),
)
);
}
add_action('init', 'mtxads_custom_post_type');
//Eine Kategorie zu den Ads
function mtxads_register_taxonomy_carcategory() {
$labels = array(
'name' => _x( 'Kategorie', 'taxonomy general name', 'mtx' ) /* Hauptüberschrift*/,
'singular_name' => _x( 'Kategorien', 'taxonomy singular name', 'mtx' ),
...
);
$args = array(
'hierarchical' => true, // make it hierarchical (like categories)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => [ 'slug' => 'mtx-carcat' ],
);
register_taxonomy( 'carcategory', [ 'mtx-ads' ], $args );
}
add_action( 'init', 'mtxads_register_taxonomy_carcategory' );
Alles anzeigen
Die Ausgabe:
PHP
<?php
while ( $mtx_ads_loop->have_posts() ) : $mtx_ads_loop->the_post();
?>
<div class="featured-home-box">
<a href="<?php the_permalink(); ?>">
<div class="blog-info-content">
<?php the_title( '<h2 class="fs-5">', '</h2>' ); ?>
</div>
</a>
<?php the_excerpt(); ?>
<span class="cat"><?php the_category()?> </span>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
Alles anzeigen
Wie bekomme ich die dazugehörige Kategorie zur Anzeige?
Vielen Dank
VG Peter G