Iterating through Object Array to customise display of full custom taxonomy for custom post type

Instead of echoing right away, save the category names into an array, and then you can implode the array, which means output it with whatever separators between items you wish: <?php if(get_the_terms($post->ID, ‘kernal_category’, true)) { // Create an empty array $categories = []; $kernal_category = get_the_terms($post->ID, ‘kernal_category’, true); // Save each category to the array … Read more

How to sort a WP_Query by a custom field AND ALSO filter by a different custom field

to sort the posts by a meta field you need to have this field in meta_query and in orderby like this $query_args = array( ‘post_type’ => ‘MY_POSTTYPE_NAME’, ‘post_per_page’ => -1, ‘meta_query’ => array( ‘show_post_query’ => array( ‘key’ => ‘SHOW_POST’, ‘value’ => ‘1’ ), ‘MY_FIELD_NAME__order_by’ => array( ‘key’ => ‘MY_FIELD_NAME’, ‘type’ => ‘NUMERIC’, ‘compare’ => ‘NUMERIC’, … Read more

Unable to edit categories in custom post type

CPT capabilities do not cover taxonomies. Each taxonomy has its own capabilities. If you want to use default Categories, unfortunately you must give user “Edit Posts” capability. There is no easy way around it, especially with Gutenberg. Best solution would be to create custom taxonomy “Event Categories” with matching capability requirements, for example, mapping all … Read more

Show message when query has no posts

Answer I found the answer, thanks to a comment and after some digging myself: function dfib_jobs_shortcode( $atts ) { ob_start(); $query = new WP_Query( array( ‘post_type’ => ‘jobpost’, ‘posts_per_page’ => -1, ‘order’ => ‘ASC’, ‘orderby’ => ‘rand’, ) ); ?> <div class=”vacatures__wrapper”> <?php if ( $query->have_posts() ) { ?> <?php while ( $query->have_posts() ) : … Read more

Include custom post type custom taxonomies in Categories widget

The widget class uses wp_list_categories() which supports all the parameters for get_terms() like taxonomy which you can use to make the widget lists categories in a taxonomy other than category. So your code would be: add_filter(‘widget_categories_args’, function( $params ) { // $params[‘post_type’] = array(‘post’, ‘recipe’); // post_type is not a standard parameter for get_terms() $params[‘taxonomy’] … Read more