Skip to content

Instantly share code, notes, and snippets.

@rachelmccollin
Last active January 17, 2018 14:05
Show Gist options
  • Save rachelmccollin/93d9852f590045bb009304ff02d2df41 to your computer and use it in GitHub Desktop.
Save rachelmccollin/93d9852f590045bb009304ff02d2df41 to your computer and use it in GitHub Desktop.
WPMU DEV WordPress: Working with Arrays
$bestcms = $cmses[0];
global $post;
$args = array(
'posts_per_page' => 3
);
$myposts = get_posts( $args );
$count = 0;
foreach ( $myposts as $post ) {
setup_postdata( $post );
$postlink[count] = get_the_permalink();
$posttitle[count] = get_the_title();
$count++;
}
wp_reset_postdata();
echo '<p>The latest posts are <a href="' . $postlink[0] . '">' . $posttitle[0] . '</a>, ' <a href="' . $postlink[1] . '">' . $posttitle[1] . '</a> and '<a href="' . $postlink[2] . '">' . $posttitle[2] . '</a>.</p>';
if ( $query->have_posts() ) {
$currentpost = 0;
while ( $query->have_posts() ) : $query->the_post();
$favorite[$currentpost] = get_the_title();
$best[$currentpost] = get_post_meta( get_the_ID(), 'Best Thing', true );
$worst[$currentpost] = get_post_meta( get_the_ID(), 'Downside', true );
$currentpost++;
endwhile;
wp_reset_postdata();
}
echo '<p>Today&apos;s Favorite Things are <b>' . $favorite[0] . '</b> plus <b>' . $favorite[1] . '</b> and a bit of <b>' . $favorite[2] . '</b> . The upsides are ' . $best[0] . ' and ' . $best[1] . ', but the downside is ' . $worst[2] . '.</p>';
$args = array(
'post_type' => 'favorite',
'posts_per_page' => 3,
'orderby' => 'rand'
);
$query = new WP_query ( $args );
$cmses = array( 'WordPress', 'Joomla', 'Drupal' );
$thing = 'text';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment