Last active
January 17, 2018 14:05
-
-
Save rachelmccollin/93d9852f590045bb009304ff02d2df41 to your computer and use it in GitHub Desktop.
WPMU DEV WordPress: Working with Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$bestcms = $cmses[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global $post; | |
$args = array( | |
'posts_per_page' => 3 | |
); | |
$myposts = get_posts( $args ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$count = 0; | |
foreach ( $myposts as $post ) { | |
setup_postdata( $post ); | |
$postlink[count] = get_the_permalink(); | |
$posttitle[count] = get_the_title(); | |
$count++; | |
} | |
wp_reset_postdata(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo '<p>Today'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>'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$args = array( | |
'post_type' => 'favorite', | |
'posts_per_page' => 3, | |
'orderby' => 'rand' | |
); | |
$query = new WP_query ( $args ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cmses = array( 'WordPress', 'Joomla', 'Drupal' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$thing = 'text'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment