How to output custom post type title on custom page with category next to it?

$leaderQuery->the_post() should only be called once, right after the loop starts: while ( $leaderQuery->have_posts() ) { $leaderQuery->the_post(); // call it just once … } I could also see you’re not correctly retrieving the ID of the current post in the loop, so the correct way is use get_the_ID(). $postCategories = get_the_category( get_the_ID() ); // like … Read more

Custom post type specific item design

I think there are many ways to do so. Here is a simple solution for the loop-template: <?php // set css class, if post-title is ‘diamond’ $cpt_class = (‘diamond’ === strtolower( $post->post_title ) ) ? ‘post-is-diamond’ : ”; ?> <!– Begin loop-template –> <article <?php post_class( $cpt_class ); ?> id=”post-<?php the_ID(); ?>”> … your stuff … Read more

Category permalinks don’t work even after flushing

The default WP category is only set-up to show posts out of the box. You should be able to expand this by doing something like the below in your functions.php: // Order course archive and taxonomy views function adjust_main_query($query){ if ( ! is_admin() && is_category() && is_category() && $query->is_main_query() ) { $query->set( ‘post_type’, array( ‘post’, … Read more

How to list posts by terms

$terms = get_terms(‘CUSTOM_TAXONOMY’, [‘hide_empty’ => true]); foreach( $terms as $term ){ echo ‘<section>’; echo ‘<h1>’ . $term->name . ‘</h1>’; $posts = get_posts([ ‘post_type’ => ‘CUSTOM_POST_TYPE’ ‘tax_query’ => [ [ ‘taxonomy’ => ‘CUSTOM_TAXONOMY’, ‘field’ => ‘term_id’, ‘terms’ => $term->term_id ] ] ]); echo ‘<ul>’; foreach($posts as $post){ echo sprintf(‘<li><a href=”%s”>%s</a></li>’, get_permalink($post), $post->post_title); } echo ‘</ul>’; echo … Read more

Is there a way to display a custom post type menu item as “users” submenu?

Solution 1 (not a good idea): add_users_page( _x( $this->page_title, “page_title”, $this->text_domain ), _x( $this->menu_title, “menu_title”, $this->text_domain ), $this->capability, “edit.php?post_type=my-post-type” ); Notice : This code is used in a class. When you are on the page, it can have some bugs with the menu, it´s a good idea for specific page Solution 2 : register_post_type( ‘my-post-type’, … Read more