Skip to content

Instantly share code, notes, and snippets.

@chocotaro chocotaro/wordpress_query.php Secret
Last active Aug 12, 2016

Embed
What would you like to do?
WordPressのクエリ操作例
<?php
//get_postsの例
$args = array('post_type' => 'post');
$the_query = get_posts( $args );
foreach ( $the_query as $post ) : setup_postdata( $post );
the_title();
endforeach;
wp_reset_postdata();
//WP_Queryの例
$args = array( 'post_type' => 'post' );
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title();
endwhile;
wp_reset_postdata();
//query_postsの例
$args = array( 'category_name=baseball' );
query_posts( $args );
while ( have_posts() ) : the_post();
the_title();
endwhile;
wp_reset_query();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.