on-internet
← Community

How to combine two foreach loops in a custom WordPress template

Stack Overflow ·

I am trying to create a custom WordPress template, and I want to combine two PHP snippets. I would like to display a list of 3 posts with a number emoji prefixed to each title. Example desired output: 1️⃣ POST TITLE 1 2️⃣ POST TITLE 2 3️⃣ POST TITLE 3 Part 1: <?php /** * Template Name: emojis LINKS SCRAPPER */ global $post; $counter = 1; $myposts = get_posts( array( 'orderby' => 'rand', 'posts_per_page' => 3, 'offset' => 0, 'category' => 187 ) ); if ( $myposts ) { foreach ( $myposts as $post ) : setup_postdata( $post ); ?> // ...do something... <?php the_title(); ?> <?php endforeach; wp_reset_

Comments

Sign in or sign up to comment and upvote.

No comments yet.