クエリー
Last updated
$posts = get_posts( 'p=12' );$query = new WP_Query( $arguments );$query->have_posts();
$query->the_post();function have_posts() {
global $wp_query;
return $wp_query->have_posts();
}$posts = get_posts( $arguments );function search_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
}
}
add_action( 'pre_get_posts', 'search_filter' );$args = array(
// args here
);
// The Query
$comments_query = new WP_Comment_Query;
$comments = $comments_query->query( $args );
// Comment Loop
if ( $comments ) {
foreach ( $comments as $comment ) {
echo '<p>' . $comment->comment_content . '</p>';
}
} else {
echo 'No comments found.';
}$args = array(
//
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
echo '<p>' . $user->display_name . '</p>';
}
} else {
echo 'No users found.';
}