Add all category as classes in foreach loop

Please replace: $new->category_slug = wp_get_post_terms($post->ID, ‘portfolio_category’)[0]->slug; with $category_slug = wp_get_post_terms($post->ID, ‘portfolio_category’); $cat_cls=””; foreach($category_slug as $cat_classes){ $cat_cls .= ” ” . $cat_classes->slug; } $new->category_slug = $cat_cls; Because the code you have written above will store only first category it will get.

Combine multiple separate lists into one

You can use a multidimensional array to get this format. Please see the example given below: $terms = get_terms( array( ‘taxonomy’ => “issueCompanion”, ‘hide_empty’ => false, ‘fields’=>’all’ ) ) $multi_arr = array(); foreach($terms as $term){ $year = get_field(‘published_year’, $term->term_id); $multi_arr[$year][] = $term->name; } When you print this $multi_arr you will get the format you want. … Read more

loop in single.php of the same category

I suggest the following: $categories = get_the_category(); $category_ids = wp_list_pluck( $categories, ‘term_id’ ); $args = [ ‘numberposts’ => 4, ‘category__in’ => $category_ids, ]; $related_posts = get_posts( $args ); $related_posts = wp_list_filter( $related_posts, [ ‘ID’ => get_queried_oject_id() ], ‘NOT’ ); if ( count( $related_posts > 3 ) ) { array_pop( $related_posts ); } global $post; foreach … Read more

Latest posts feed with a specific post always first

Since you’re using get_posts() rather than WP_Query, it’s sufficient to retrieve the specific post separately with get_post(), and then add it to the beginning of the results array with array_unshift(): $postslist = get_posts( $args ); $featured_post = get_post( 123 ); array_unshift( $postslist, $featured_post ); foreach ( $postslist as $post ) : setup_postdata($post);