wordpress query category code example

Example 1: category name wp query

$query = new WP_Query( array( 'category_name' => 'staff' ) );

cat (int)use category id.
category_name (string)use category slug.
category__and (array)use category id.
category__in (array)use category id.
category__not_in (array)use category id.

Example 2: wp query

<?php 
// The Query
$the_query = new WP_Query( $args );
 
// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

Tags:

Sql Example