Skip to content

Instantly share code, notes, and snippets.

@chocotaro
Last active August 12, 2016 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chocotaro/f6fe90d876631bdc9fa80c760cd2b44f to your computer and use it in GitHub Desktop.
Save chocotaro/f6fe90d876631bdc9fa80c760cd2b44f to your computer and use it in GitHub Desktop.
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